The NodeJS Blogs API is a backend application that provides RESTful API endpoints for managing blog posts. It allows users to perform CRUD (Create, Read, Update, Delete) operations on blog posts and associated metadata. This API is designed to be used as a backend service for a blogging platform or any other application that requires blog post management.
- Create a new blog post with title, content, author, and any additional metadata.
- Retrieve a list of all blog posts or fetch a specific blog post by its ID.
- Update an existing blog post, modify its content, or update its metadata.
- Delete a blog post and its associated data from the system.
- User authentication and authorization for protected endpoints.
Before running the application, ensure you have the following prerequisites:
- Clone the repository to your local machine:
git clone https://github.com/islombek124/blogs-api.git
- Navigate to the project directory:
cd blogs-api
- Install the required dependencies:
npm install
Copy the .env.example
file to .env
and update the configurations as per your environment:
cp .env.example .env
Make sure to set the correct MongoDB connection URL and any other required configurations in the .env
file.
Start the NodeJS server by running the following command:
npm run dev
By default, the server will run on http://localhost:3000
, but you can configure the port in the .env
file.
The following API endpoints are available:
GET /blogs
: Get all blog posts.GET /blogs/:id
: Get a specific blog post by ID.POST /blog
: Create a new blog post.DELETE /delete-blog
: Delete a blog post.
For detailed information about the request and response formats, see the API documentation or the source code.
Certain API endpoints may require authentication. In the current setup, we are using JWT (JSON Web Tokens) for authentication. Users must obtain a valid token by sending a login request to the appropriate endpoint with valid credentials.
Example Login Endpoint: POST /login
Upon successful login, the API will provide a JWT token that needs to be included in the Authorization
header for protected endpoints.
The API follows standard HTTP status codes and provides error responses in JSON format. In case of an error, the response will contain relevant information about the error, such as error code, message, and possibly additional details.
To run the test suite, execute the following command:
npm test
The tests cover different use cases and edge scenarios to ensure the correctness of the application.
We welcome contributions to improve the project. To contribute, follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them with descriptive commit messages.
- Push your changes to your forked repository.
- Create a pull request to the main repository.
We will review your pull request and provide feedback as soon as possible.
This project is licensed under the MIT License. Feel free to use, modify, and distribute it as per the terms of the license.