Skip to content

islomurodov/blogs-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NodeJS Blogs API

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.

Table of Contents

Features

  • 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.

Getting Started

Prerequisites

Before running the application, ensure you have the following prerequisites:

Installation

  1. Clone the repository to your local machine:
git clone https://github.com/islombek124/blogs-api.git
  1. Navigate to the project directory:
cd blogs-api
  1. Install the required dependencies:
npm install

Configuration

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.

Running the Application

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.

API Endpoints

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.

Authentication

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.

Error Handling

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.

Testing

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.

Contributing

We welcome contributions to improve the project. To contribute, follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them with descriptive commit messages.
  4. Push your changes to your forked repository.
  5. Create a pull request to the main repository.

We will review your pull request and provide feedback as soon as possible.

License

This project is licensed under the MIT License. Feel free to use, modify, and distribute it as per the terms of the license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published