A small REST API for a blog backend that supports user registration, authentication (JWT), and CRUD operations for posts.
Base URL: http://localhost:5000/api
All protected endpoints require an Authorization header with a valid JWT in the form:
Authorization: Bearer
- Method: POST
- Endpoint:
/auth/register - Body (application/json):
{
"name": "username",
"email": "username@example.com",
"password": "password123"
}- Success response:
{
"success": true,
"user": {
"id": "691304cf9de42bb85b363089",
"name": "username",
"email": "username@example.com",
"token": "<jwt-token>"
}
}- Method: POST
- Endpoint:
/auth/login - Body (application/json):
{
"email": "username@example.com",
"password": "password123"
}- Success response:
{
"success": true,
"user": {
"id": "691304cf9de42bb85b363089",
"name": "username",
"email": "username@example.com",
"token": "<jwt-token>"
}
}Public and protected endpoints to create, read, update and delete posts.
- Method: POST
- Endpoint:
/posts - Headers:
Authorization: Bearer <token>,Content-Type: application/json - Body:
{
"title": "My first blog",
"body": "This is the body"
}- Success response:
{
"title": "My first blog",
"body": "This is the body",
"author": "691304cf9de42bb85b363089",
"_id": "691305509de42bb85b36308c",
"createdAt": "2025-11-11T09:43:44.899Z",
"updatedAt": "2025-11-11T09:43:44.899Z",
"__v": 0
}- Method: GET
- Endpoint:
/posts - Success response:
[
{
"_id": "691305509de42bb85b36308c",
"title": "My first blog",
"body": "This is the body",
"author": {
"_id": "691304cf9de42bb85b363089",
"name": "username",
"email": "username@example.com"
},
"createdAt": "2025-11-11T09:43:44.899Z",
"updatedAt": "2025-11-11T09:43:44.899Z",
"__v": 0
},
{
"_id": "691302839de42bb85b363081",
"title": "My first blog",
"body": "This is the body",
"author": {
"_id": "6912ff694b19de0cf779766b",
"name": "Sanjay",
"email": "sanjay@example.com"
},
"createdAt": "2025-11-11T09:31:47.539Z",
"updatedAt": "2025-11-11T09:31:47.539Z",
"__v": 0
}
]- Method: PUT
- Endpoint:
/posts/<postId> - Headers:
Authorization: Bearer <token>,Content-Type: application/json - Body: partial or full (example):
{
"title": "My first blog updated"
}- Success response:
{
"_id": "691305509de42bb85b36308c",
"title": "My first blog updated",
"body": "This is the body",
"author": "691304cf9de42bb85b363089",
"createdAt": "2025-11-11T09:43:44.899Z",
"updatedAt": "2025-11-11T09:45:04.602Z",
"__v": 0
}- Method: DELETE
- Endpoint:
/posts/<postId> - Headers:
Authorization: Bearer <token> - Success response:
{
"message": "Post deleted successfully"
}