Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sanjithrk06/blog

A RESTful API for managing blogs with user authentication.
https://github.com/sanjithrk06/blog

expressjs jwt-authentication mongodb nodejs rest-api

Last synced: 2 months ago
JSON representation

A RESTful API for managing blogs with user authentication.

Awesome Lists containing this project

README

        

# **Blog Platform(RESTful API)**

## Project Overview

A RESTful API for managing blogs with user authentication. This API allows users to create, read, update, and delete blog posts, while ensuring only authenticated users have access to the blog-related functionality. User registration and login are secured using JWT tokens for authentication.

---
## Tech Stack

**Server:** Node.js, Express.js

**Database:** MongoDB

**ODM Tool:** Mongoose

**Authentication:** JWT (JSON Web Token)

**Password Security:** bcrypt.js for password hashing

---
## Key features

- **User Management:** Endpoints for user registration, login, and profile access.
- **Blog Management:** Endpoints for creating, reading, updating, and deleting blog posts.
- **JWT Authentication:** Secure access to blog routes using JWT tokens.
- **Protected Routes:** Only authenticated users can create, update, or delete blog posts.
- **Error Handling:** Graceful error handling for all endpoints.

---
## Environment Variables

To run this project, you will need to add the following environment variables to your .env file:

```env
PORT=
MONGO_URI=
JWT_SECRET=
```

---
## Run Locally

1. **Clone the project**

```bash
https://github.com/sanjithrk06/Blog-Platform.git
```

2. **Go to the project directory**

```bash
cd Blog-Platform
```

3. **Install dependencies**

```bash
npm install
```

4. **Create a .env file**

Add the required environment variables as shown above.

5. **Start the server**

```bash
npm run start
```

The server will start on the port you specified in the .env file or on port 3000 by default.

---
## API Documentation

#### Auth Routes

| | Method | End Point | Description |
| :--------- | :------- | :------------- | :---------------------- |
| **Signup** | **POST** | `/auth/signup` | Register a new user |
| **Login** | **POST** | `/auth/login` | Log in an existing user |

#### Blog Routes

| Method | End Point | Description |
| :--------- | :---------- | :---------------- |
| **GET** | `/blog` | Get all blogs |
| **POST** | `/blog` | Create a new blog |
| **PUT** | `/blog/:id` | Update a blog |
| **DELETE** | `/blog/:id` | Delete a blog |

#### Request Headers

For protected routes, include the JWT token in the headers:

```json
{
"Authorization": "Bearer "
}
```

---
## License

This project is licensed under the MIT License. You are free to use, modify, and distribute it as you see fit.

---