Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mtpontes/blog-san-api
Blog-san is a blog API, where users can create posts, comments and reply to comments.
https://github.com/mtpontes/blog-san-api
integration-testing jwt-token rest-api spring-boot spring-security test-containers unit-testing
Last synced: 5 days ago
JSON representation
Blog-san is a blog API, where users can create posts, comments and reply to comments.
- Host: GitHub
- URL: https://github.com/mtpontes/blog-san-api
- Owner: mtpontes
- License: mit
- Created: 2024-02-08T00:29:36.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-07-10T22:46:28.000Z (7 months ago)
- Last Synced: 2024-07-25T15:08:45.233Z (6 months ago)
- Topics: integration-testing, jwt-token, rest-api, spring-boot, spring-security, test-containers, unit-testing
- Language: Java
- Homepage:
- Size: 293 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Blog-san API
Blog-san is a simple REST API project, with the intention of practicing, CRUD, mapping and entity relationships. There, users can create an account, publish, comment and respond.
## 🛠️ Tecnologies
- [Spring Boot](https://spring.io/projects/spring-boot)
- [Docker](https://www.docker.com)
- [Test Containers](https://testcontainers.com)
- [Java JWT](https://github.com/auth0/java-jwt)
- [MySQL](https://dev.mysql.com/downloads/connector/j/)
- [Springdoc OpenAPI](https://springdoc.org/)## ⚙️ Functionalities
- [x] User registration;
- [x] Authentication and authorization;
- [x] CRUD for publications and comments;
- [x] Public acces for readers, but without interactions with publications and other users;
- [x] Relationships between publications to comments and comments to comments;
📖 How to use
### Documentation
The documentation can be accessed after deploying the application via the URL http://localhost:8080/swagger-ui/index.html#/
You can also import my set of requests into Postman. There you have all the endpoints with all the necessary URL parameters and body details to interact with the API.
[](https://app.getpostman.com/run-collection/31232249-755011b3-0b0f-4120-9699-7677b4c10832?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D31232249-755011b3-0b0f-4120-9699-7677b4c10832%26entityType%3Dcollection%26workspaceId%3Daae15406-ac2a-4087-8c9e-47072e8aa119)
## Examples
##### Note: All `GET` request endpoints are accessible without authentication.By default, all users are created with the USER role, these users can only create comments on posts. To become an ADMIN and be able to create posts, you can use the system's default ADMIN user:
#### Default user ADMIN
- **login**: root
- **password**: rootThis way you can authenticate as ADMIN to have the freedom to create posts and even other ADMINs in the system.
---
### Register
To create posts and comments, you need to register:
**POST:** `/auth/register`
**Content-Type: application/json**
```
{
"login": "newUser",
"password": "newPassword",
"name": "Example Name",
"email": "[email protected]"
}
```
---### Login
After registering, you need to authenticate:
**POST:** `/auth/login`
**Content-Type: application/json**```
{
"login": "root",
"password": "root",
}
```**Response:**
```
{
"token": "your_access_token"
}
```This access token will be your 'free pass' to create posts and comments
---
### Using the access token
After receiveing the successful access token, you need to include the header for your future requests. The access token must be passed as parte of the "Authorization" title.
**Header example:**
```
Authorization: Bearer your_access_token
```---
### Publication creation
**POST:** `/publications`
```
{
"description": "Publication content",
"imageLink": "link_for_image"
}
```**Response:**
```
{
"publicationId": 1,
"userId": 1,
"nameUser": "Your User Name",
"description": "Publication content",
"imageLink": "link_for_image",
"date": "2024-02-10 19:13"
}
```
---### Comment creation
**POST:** `/publications/{publicationId/comments`
```
{
"publicationId": 1,
"text": "Comment example"
}
```**Response:**
```
{
"commentId": 1,
"userId": 1,
"text": "Comment example",
"date": "2024-02-10 19:10",
"edited": false
}
```
---#### These are basic examples, and you can explore other endpoints as needed. Be sure to replace the dummy values with actual data from your development environment.
🚀 How to run
The application is configured to connect to MySQL via port 3306.
### Environment variables:
#### Database| ENV | DEFAULT VALUE | DESCRIPTION |
| ---------- | --- | ------------- |
| `DB_USERNAME` | root | Database username |
| `DB_PASSWORD` | root | Database password |#### Security
| ENV | DEFAULT VALUE | DESCRIPTION |
| ---------- | --- | ------------- |
| `JWT_SECRET` | secret | JWT token secret |## Run
Clone this repository:
git clone https://github.com/mtpontes/blog-san-api.git
### Deploy with Docker
#### Prerequisites- Docker
- Docker Compose#### Deploy
Raise the containers:
docker-compose up --build