TimeTalk API is a RESTFul API created to be used in a social network to ask questions, share experiences and make comments.
- Java 22
- Spring Boot 3
- Spring Security
- JWT
- JPA/Hibernate
- MySQL
- Docker
The API has been containerized using Docker. A Dockerfile and a docker-compose.yml file are included. Also, the image is available on DockerHub under the name christian471/timetalk-api
.
The features of the API are the next:
- Create an account
- Login
- CRUD operations:
- Additional features:
- Error handling (Exceptions)
- Method:
POST
- Route:
/api/v1/auth/signup
- Description: Create a new account and obtain a JWT token. Follow the password best practices (minimum length of 8 characters, and use of a number) for security. Specify the role USER.
- Request Body:
{
"firstName": "Christian",
"lastName": "Ramírez",
"email": "[email protected]",
"password": "mypasswordissecure123",
"roleRequest": {
"roleListName": [
"USER"
]
}
}
- Response:
- Status Code:
200
- Response Body:
- Status Code:
{
"email": "[email protected]",
"jwt": "JWT_TOKEN",
"status": true,
"message": "User created successfully"
}
- Method:
POST
- Route:
/api/v1/auth/login
- Description: Authenticate a user and obtain a JWT token.
- Request Body:
{
"email": "[email protected]",
"password": "mypasswordissecure123"
}
- Response:
- Status Code:
200
- Response Body:
- Status Code:
{
"email": "[email protected]",
"jwt": "JWT_TOKEN",
"status": true,
"message": "User logged successfully."
}
- Method:
GET
- Route:
/api/v1/posts
- Description: Returns all available posts. You must include a valid JWT in the
Authorization
header of the request. For example:Authorization: Bearer YOUR_JWT_TOKEN
- Response:
- Status Code:
200
- Response Body:
- Status Code:
[
{
"id": 1,
"author": {
"firstName": "John",
"lastName": "Doe"
},
"creationDate": "2024-10-08T08:00:51.492769",
"title": "What do you think of dive watches?",
"description": "I've always wanted a dive watch. Does anyone have recommendations or brands worth considering?",
"likes": [],
"comments": []
},
{
"id": 2,
"author": {
"firstName": "John",
"lastName": "Doe"
},
"creationDate": "2024-10-08T08:47:54.180589",
"title": "What features do you value most in a watch?",
"description": "I'm trying to decide what to look for in my next watch. Is it the design, the mechanism, or perhaps water resistance?",
"likes": [
{
"user": {
"firstName": "Christian",
"lastName": "Ramírez"
}
}
],
"comments": [
{
"author": {
"firstName": "Christian",
"lastName": "Ramírez"
},
"creationDate": "2024-10-08T08:48:50.231948",
"content": "I personally prioritize the durability and water resistance. It's important for me to have a watch that can withstand everyday activities. What about others?"
}
]
}
]
- Method:
POST
- Route:
/api/v1/posts
- Description: Create a new post. You must include a valid JWT in the
Authorization
header of the request. For example:Authorization: Bearer YOUR_JWT_TOKEN
- Request Body:
{
"title": "What do you think of dive watches?",
"description": "I've always wanted a dive watch. Does anyone have recommendations or brands worth considering?"
}
- Response:
- Status Code:
200
- Response Body:
- Status Code:
{
"id": 1,
"author": {
"firstName": "Christian",
"lastName": "Ramírez"
},
"creationDate": "2024-10-08T08:59:40.9176076",
"title": "What do you think of dive watches?",
"description": "I've always wanted a dive watch. Does anyone have recommendations or brands worth considering?",
"likes": [],
"comments": []
}
- Method:
PUT
- Route:
/api/v1/posts/{post-id}
- Description: Updates an existing post. The
{post-id}
parameter should be replaced with the ID of the post you want to update. Only the author of the post can access this endpoint. You must include a valid JWT in theAuthorization
header of the request. For example:Authorization: Bearer YOUR_JWT_TOKEN
- Request Body:
{
"title": "What features are essential for a dive watch?",
"description": "I’m interested in getting a dive watch, but I'm curious about what features really matter. Is it just about water resistance, or should I consider other factors like visibility and durability?"
}
- Response:
- Status Code:
200
- Response Body:
- Status Code:
{
"id": 2,
"author": {
"firstName": "Christian",
"lastName": "Ramírez"
},
"creationDate": "2024-10-08T09:08:18.681976",
"title": "What features are essential for a dive watch?",
"description": "I’m interested in getting a dive watch, but I'm curious about what features really matter. Is it just about water resistance, or should I consider other factors like visibility and durability?",
"likes": [],
"comments": []
}
- Method:
DELETE
- Route:
/api/v1/posts/{post-id}
- Description: Deletes an existing post. The
{post-id}
parameter should be replaced with the ID of the post you want to delete. Only the author of the post can access this endpoint. You must include a valid JWT in theAuthorization
header of the request. For example:Authorization: Bearer YOUR_JWT_TOKEN
. - Request Body: None
- Response:
- Status Code:
204
- Response Body: None
- Status Code:
- Method:
POST
- Route:
/api/v1/posts/{post-id}/comments
- Description: Add a comment to an existing post. The
{post-id}
parameter should be replaced with the ID of the post you want to comment. You must include a valid JWT in theAuthorization
header of the request. For example:Authorization: Bearer YOUR_JWT_TOKEN
. - Request Body:
{
"content": "I think visibility is crucial for a dive watch, especially in low-light conditions. A good bezel and clear markings can make a big difference underwater."
}
- Response:
- Status Code:
201
- Response Body:
- Status Code:
{
"author": {
"firstName": "Christian",
"lastName": "Ramírez"
},
"creationDate": "2024-10-08T09:13:55.4522113",
"content": "I think visibility is crucial for a dive watch, especially in low-light conditions. A good bezel and clear markings can make a big difference underwater."
}
- Method:
POST
- Route:
/api/v1/posts/{post-id}/likes
- Description: Add a like to an existing post. The
{post-id}
parameter should be replaced with the ID of the post you want to give a like. A user cannot like the same post more than once. The author of the post is not allowed to like their own post. You must include a valid JWT in theAuthorization
header of the request. For example:Authorization: Bearer YOUR_JWT_TOKEN
. - Request Body: None
- Response:
- Status Code:
200
- Response Body:
- Status Code:
{
"postId": 1,
"totalLikes": 1
}
-
Method:
DELETE
-
Route:
/api/v1/posts/{post-id}/likes
-
Description: Remove a like from an existing post. The
{post-id}
parameter should be replaced with the ID of the post from which you want to remove the like. Only the user who previously liked the post can use this endpoint. You must include a valid JWT in theAuthorization
header of the request. For example:Authorization: Bearer YOUR_JWT_TOKEN
. -
Request Body: None
-
Response:
- Status Code:
204
- Response Body: None
- Status Code:
- Method:
GET
- Route:
/api/v1/users/profile
- Description: Get first name and last name from the authenticated user. Only the authenticated user can access this endpoint. You must include a valid JWT in the
Authorization
header of the request. For example:Authorization: Bearer YOUR_JWT_TOKEN
. - Request Body: None
- Response:
- Status Code:
200
- Response Body:
- Status Code:
{
"firstName": "Christian",
"lastName": "Ramírez"
}