The blog-api is designed to manage posts, comments, user registration, and authentication using a JWT token. Below, we’ll delve into the specifics of this API.
-
- Endpoint: POST
/user/sign-up
- Description: Registers a new user.
- Request Format:
{ "name": "example_user", "email": "example@example.com", "password": "your_password" }
- Response Format: Success message or error message.
- Endpoint: POST
-
- Endpoint: POST
/user/login
- Description: Logs in a user.
- Request Format:
{ "email": "example@example.com", "password": "your_password" }
- Response Format: JSON object containing JWT token or error message.
- Endpoint: POST
-
- Endpoint: GET
/posts
- Description: Fetches a list of all blog posts.
- Response Format: JSON array containing post objects.
- Authentication: No authentication required.
- Endpoint: GET
-
- Endpoint: GET
posts/:postId
- Description: Retrieves details of a specific post.
- Response Format: JSON object representing the post.
- Authentication: No authentication required.
- Endpoint: GET
-
- Endpoint: POST
/posts
- Description: Creates a new blog post.
- Request Format:
{ "title": "Sample Post", "content": "This is a sample post content." }
- Response Format: JSON object representing the newly created post.
- Authentication: Requires a valid JWT token.
- Endpoint: POST
-
- Endpoint: PUT
posts/:postId
- Description: Updates an existing post.
- Request Format: JSON object with updated post content.
- Response Format: JSON object representing the updated post.
- Authentication: Requires a valid JWT token.
- Endpoint: PUT
-
- Endpoint: DELETE
posts/:postId
- Description: Deletes a specific post.
- Response Format: Success message.
- Authentication: Requires a valid JWT token.
- Endpoint: DELETE
-
- Endpoint: GET
test/associations
- Endpoint: GET
-
- Endpoint: POST
/category
- Description: Creates new category.
- Response Format: Success message with category details.
- Endpoint: POST
To access protected endpoints (create, update, delete), include a valid JWT token in the request headers.
Obtain the token by authenticating via the login endpoint (POST user/sign-up
, POST user/login
).