GithubHelp home page GithubHelp logo

im-awesome-aadi / blog-rest-api Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 37 KB

This REST API is for blog website, where user can create edit and delete posts. Read "README" for more detailed insights

Home Page: https://anime-aadi.herokuapp.com/feed

JavaScript 99.88% Procfile 0.12%
nodejs expressjs mongodb authentication-middleware validation

blog-rest-api's Introduction

REST API for Blog Website

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.

END POINTS

Sign Up

Request

PUT /auth/signup

Request Body

{ "email":"[email protected]", "password":"123456", "name": "Aditya" }

Response

{ "message": "Account created successfully", "userId": "60b642c1fa358a00046003e9" }

LOGIN

Request

POST /auth/login

Request Body

{ "email":"[email protected]", "password":"123456" }

Response

{ "message": "Token generated successfully", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImFkaXR5YUBnaXRodWIuY29tIiwidXNlcklkIjoiNjBiNjQyYzFmYTM1OGEwMDA0NjAwM2U5IiwiaWF0IjoxNjIyNTU3NDc2LCJleHAiOjE2MjI1NjEwNzZ9.o5raRC9-cAz4qn9Gx63ubmHFX4ZQgDrlvJQBCsniqr8", "userId": "60b642c1fa358a00046003e9" } This JWT token expires in 1h

SHOWING FEED OF POSTS

Request

GET /feed/?page=1

Authorization is not required for this route. Each page shows 3 posts.

Response

{ "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" } ] }

SHOWING EACH POST

Request

GET /post/:postId

Authorization is not required for this route

Request Params

Key Value
postId Unique Id of each post

post id can be found using GET/feed route

Response

{ "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" ] } }

CREATING A POST

Request

POST /createpost

Authorization is required for this route

Request Header

Key Value
Authorization JWT Token

JWT token is received while logging-in by POST/auth/login route

Request Body

{ "title":"First Post", "content":"This is my First Post" }

Response

{ "message": "Post created successfully!", "post": { "id": "60b646a0fa358a00046003ea", "title": "First Post", "content": "This is my First Post" } }

EDITING A POST

Request

POST /editpost

Authorization is required for this route

Request Header

Key Value
Authorization JWT Token

JWT token is received while logging-in by POST/auth/login route

Request Body

{ "postId": "60b646a0fa358a00046003ea", "title":"Second Post", "content":"This is was not my First Post. This was last post" }

Response

{ "message": "Post Edited successfully!", "post": { "title": "Second Post", "content": "This is not my First Post" } }

DELETING A POST

Request

POST /deletepost

Authorization is required for this route

Request Header

Key Value
Authorization JWT Token

JWT token is received while logging-in by POST/auth/login route

Request Body

{ "postId": "60b646a0fa358a00046003ea" }

Response

{ "message": "Deleted successfully" }

Any endpoints other than mentioned above will produce the below shown response.
{ "message": "Page not found" }

Found this project useful? ❤️

If you found this project useful, then please consider giving it a ⭐ on Github and sharing it with your friends via social media.

Project Created & Maintained By

Aditya Maheshwari

Nodejs Developer #Nodejs, #backend

blog-rest-api's People

Contributors

im-awesome-aadi avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.