This API allows users to manage blog posts, comments, and user authentication. It supports two roles: Admin and User.
https://backend-uoiu.onrender.com/api/posts
- POST
/users/register- Request Body:
{ "username": "string", "email": "string", "password": "string" } - Response:
- 201 Created: User registered successfully.
- 400 Bad Request: Validation errors.
- Request Body:
- POST
/users/login- Request Body:
{ "email": "string", "password": "string" } - Response:
- 200 OK: Successful login, returns a JWT token.
- 401 Unauthorized: Invalid credentials.
- Request Body:
- GET
/users- Response:
- 200 OK: Returns an array of users.
- 403 Forbidden: Access denied for non-admin users.
- Response:
- POST
/posts- Request Body:
{ "title": "string", "content": "string", "published": "boolean" } - Response:
- 201 Created: Post created successfully.
- 403 Forbidden: Access denied for non-admin users.
- Request Body:
- GET
/posts- Response:
- 200 OK: Returns an array of all posts.
- Response:
- GET
/posts/:id- Response:
- 200 OK: Returns the requested post.
- 404 Not Found: Post does not exist.
- Response:
- PUT
/posts/:id- Request Body:
{ "title": "string", "content": "string", "published": "boolean" } - Response:
- 200 OK: Post updated successfully.
- 403 Forbidden: Access denied for non-admin users.
- 404 Not Found: Post does not exist.
- Request Body:
- DELETE
/posts/:id- Response:
- 204 No Content: Post deleted successfully.
- 403 Forbidden: Access denied for non-admin users.
- 404 Not Found: Post does not exist.
- Response:
- POST
/posts/:postId/comments- Request Body:
{ "content": "string" } - Response:
- 201 Created: Comment added successfully.
- 404 Not Found: Post does not exist.
- Request Body:
- GET
/posts/:postId/comments- Response:
- 200 OK: Returns an array of comments for the specified post.
- 404 Not Found: Post does not exist.
- Response:
- DELETE
/comments/:id- Response:
- 204 No Content: Comment deleted successfully.
- 403 Forbidden: Access denied for non-admin users.
- 404 Not Found: Comment does not exist.
- Response:
- The API will return appropriate HTTP status codes and error messages for all invalid requests or actions.