Welcome to the Blogging API project! This API was created as a challenge inspired by roadmap.sh, aimed at honing skills in MongoDB, Node.js, asynchronous programming, and problem-solving.
- Create, read, update, and delete blog posts
- User authentication and authorization
- Comment on posts
- Like and dislike posts
- Filter posts by categories and tags
- Search functionality
-
Clone the repository:
git clone https://github.com/yourusername/blogging-api.git cd blogging-api -
Install the dependencies:
npm install
-
Create a
.envfile in the root directory and add your MongoDB URI and other environment variables:MONGO_URI=your_mongodb_uri JWT_SECRET=your_jwt_secret
-
Start the server:
npm start
-
Using Postman to test the API:
- Open Postman.
- Load the API endpoints to interact with the Blogging API.
-
Register a new user
POST /api/auth/register
- Body:
{ "username": "string", "email": "string", "password": "string" }
- Body:
-
Login
POST /api/auth/login
- Body:
{ "email": "string", "password": "string" }
- Body:
-
Create a new post
POST /api/posts
- Headers:
{ "Authorization": "Bearer <token>" } - Body:
{ "title": "string", "content": "string", "tags": ["string"], "category": "string" }
- Headers:
-
Get all posts
GET /api/posts
-
Get a single post
GET /api/posts/:id
-
Update a post
PUT /api/posts/:id
- Headers:
{ "Authorization": "Bearer <token>" } - Body:
{ "title": "string", "content": "string", "tags": ["string"], "category": "string" }
- Headers:
-
Delete a post
DELETE /api/posts/:id
- Headers:
{ "Authorization": "Bearer <token>" }
- Headers:
-
Add a comment to a post
POST /api/posts/:id/comments
- Headers:
{ "Authorization": "Bearer <token>" } - Body:
{ "content": "string" }
- Headers:
-
Get comments for a post
GET /api/posts/:id/comments
-
Delete a comment
DELETE /api/posts/:postId/comments/:commentId
- Headers:
{ "Authorization": "Bearer <token>" }
- Headers:
Contributions are welcome! Please fork the repository and submit a pull request.
This project is licensed under the MIT License.