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;
๐ข Integrations between publications to comments and comments to comments;
- Clone this repository
- Run the command
mvn spring-boot:run
in the root directory or import the Maven project and run it in your IDE - Access the URL http://localhost:8080
- All
GET
request endpoints are accessible without authentication.
- 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]"
}
By default, all users are created with the USER
role.
To become an ADMIN
, you need to change your role
attribute in the database. There is an endpoint capable of creating users with the ADMIN role, but only users with the ADMIN role can access it.
- 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
}
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.
- To access the complete project documentation, implemented with SpringDoc OpenApi, visit http://localhost:8080/swagger-ui/index.html when the application is running.
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.