Entire project is build using Nodejs and its related libraries (can be found in package.json file)
This project includes all the major backend concepts like Error Handling, Authentication, Pagination etc.
This API includes server side validation and authentication using JWT token.
After signing-up with email-ID and choosing an user name, user's email-ID, name and password (hashed password) is stored in the database (MongoDB is used). As a user, you can create,read, edit and delete the posts. And obviously one can delete or edit his own posts. Posts created by one users is visible to all, but can only be edited/deleted by the owner of that post.
Now, lets see the endpoints of this API.
PUT /auth/signup
{ "email":"[email protected]", "password":"123456", "name": "Aditya" }
{ "message": "Account created successfully", "userId": "60b642c1fa358a00046003e9" }
POST /auth/login
{ "email":"[email protected]", "password":"123456" }
{ "message": "Token generated successfully", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFkaXR5YUBnaXRodWIuY29tIiwidXNlcklkIjoiNjBiNjQyYzFmYTM1OGEwMDA0NjAwM2U5IiwiaWF0IjoxNjIyNTU3NDc2LCJleHAiOjE2MjI1NjEwNzZ9.o5raRC9-cAz4qn9Gx63ubmHFX4ZQgDrlvJQBCsniqr8", "userId": "60b642c1fa358a00046003e9" }
This JWT token expires in 1h
GET /feed/?page=1
Authorization is not required for this route. Each page shows 3 posts.
{ "message": "All posts found successfully", "posts": [ { "_id": "60b342b23036ad05000f569d", "title": "My post mna", "content": "Sorry sorry please", "createdAt": "2021-05-30T07:45:54.703Z", "userId": "60b28712c8f62d28c481a746" } ] }
GET /post/:postId
Authorization is not required for this route
Key | Value |
---|---|
postId | Unique Id of each post |
post id can be found using GET/feed route
{ "message": "found successfully", "posts": { "_id": "60b646a0fa358a00046003ea", "title": "Second Post", "content": "This is not my First Post", "createdAt": "2021-06-01T14:39:28.153Z", "userId": "60b642c1fa358a00046003e9", "updatedTime": [ "2021-06-01T14:43:44.663Z" ] } }
POST /createpost
Authorization is required for this route
Key | Value |
---|---|
Authorization | JWT Token |
JWT token is received while logging-in by POST/auth/login route
{ "title":"First Post", "content":"This is my First Post" }
{ "message": "Post created successfully!", "post": { "id": "60b646a0fa358a00046003ea", "title": "First Post", "content": "This is my First Post" } }
POST /editpost
Authorization is required for this route
Key | Value |
---|---|
Authorization | JWT Token |
JWT token is received while logging-in by POST/auth/login route
{ "postId": "60b646a0fa358a00046003ea", "title":"Second Post", "content":"This is was not my First Post. This was last post" }
{ "message": "Post Edited successfully!", "post": { "title": "Second Post", "content": "This is not my First Post" } }
POST /deletepost
Authorization is required for this route
Key | Value |
---|---|
Authorization | JWT Token |
JWT token is received while logging-in by POST/auth/login route
{ "postId": "60b646a0fa358a00046003ea" }
{ "message": "Deleted successfully" }
Any endpoints other than mentioned above will produce the below shown response.
{ "message": "Page not found" }
If you found this project useful, then please consider giving it a ⭐ on Github and sharing it with your friends via social media.