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.
- User registration;
- Authentication and authorization;
- CRUD for publications and comments;
- Public acces for readers, but without interactions with publications and other users;
- Relationships between publications to comments and comments to comments;
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.
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:
- login: root
- password: root
This way you can authenticate as ADMIN to have the freedom to create posts and even other ADMINs in the system.
To create posts and comments, you need to register:
POST: /auth/register
Content-Type: application/json
{
"login": "newUser",
"password": "newPassword",
"name": "Example Name",
"email": "example@email.com"
}
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
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
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"
}
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
}
The application is configured to connect to MySQL via port 3306.
ENV | DEFAULT VALUE | DESCRIPTION |
---|---|---|
DB_USERNAME |
root | Database username |
DB_PASSWORD |
root | Database password |
ENV | DEFAULT VALUE | DESCRIPTION |
---|---|---|
JWT_SECRET |
secret | JWT token secret |
Clone this repository:
git clone https://github.com/mtpontes/blog-san-api.git
- Docker
- Docker Compose
Raise the containers:
docker-compose up --build