A feature rich REST API for blog-like applications using Node.js.
Handles image-upload, uses web-sockets for live feed, authentication using JWT and e-mail verification using SendGrid.
- Clone this repo:
git clone https://github.com/guptapriyanshu7/rest-api
- Run
npm install
- Setup environment variables :
- Create a
.env
file in root directory of the project - Insert these 3 keys/value pairs :
- PORT : < Port on which server will listen >
- MONGO_URI : < Mongo database connection URI >
- SENDGRID_API_KEY : < Api key for sendgrid. >
- Create a
- Start the server:
npm start
- Start requesting the server.
The app defines following CRUD APIs.
Method | Url | Description |
---|---|---|
POST | /api/login | Login via e-mail and password. |
POST | /api/signup | Signup requires email and password. |
GET | /api/status | Returns the status of user. |
PATCH | /api/status | Updates the status of user. |
POST | /api/verify/{token} | Matches the token and sets the user as verified. |
POST | /api/change-password | To change the password of user. |
POST | /api/reset | Send reset token to validate user. |
GET | /api/reset/{token} | Match token to complete verification. |
Method | Url | Description |
---|---|---|
GET | /api/posts | Returns all the posts. |
POST | /api/post | Creates a post using title and content. |
GET | /api/post/{id} | Get the post by id. |
PUT | /api/post/{id} | Update post. |
DELETE | /api/post/{id} | Delete post from database. |
rest-api
├── controllers (Functions to run when an API endpoint is hit.)
│ ├── auth.js
│ └── feed.js
├── images (Uploaded images are stored here.)
├── index.js
├── middlewares (Auth middleware.)
│ └── isAuth.js
├── models (MongoDB models.)
│ ├── post.js
│ └── user.js
├── package.json
├── package-lock.json
├── routes (API endpoints.)
│ ├── auth.js
│ └── feed.js
├── test (Tests to the application.)
│ ├── auth-controller.js
│ ├── auth-middleware.js
│ ├── feed-controller.js
│ └── start.js
└── utils (Utilities folder.)
└── socket.js
GraphQL alternative - https://github.com/guptapriyanshu7/graphql
This project is licensed under the MIT License, © 2021 Priyanshu Gupta. See LICENSE for more details.