This README provides detailed instructions on how to use the backend API, including available routes and setup steps.
-
POST Sign Up
- Route:
/api/user/signUp - Parameters:
username,password - Returns a JSON object acknowledging success.
- Route:
-
POST Sign In
- Route:
/api/user/signIn - Parameters:
username,password - Returns a JSON object with the following format:
{ "token": "string" }
After signing in, you will receive a token that you must include in your 'Bearer token headers' to authenticate yourself.
- Route:
-
GET View All Blogs
- Route:
/api/blog - Returns an array of blogs, each containing the following fields:
idtitlecontentcreatedAtupdatedAt
- Route:
-
GET View Blog
- Route:
/api/blog/{blogId} - Returns a single blog with the following fields:
idtitlecontentcreatedAtupdatedAt
- Route:
-
POST Create Blog
- Route:
/api/blog - Parameters:
title,content - Creates a new blog and returns the created blog with the following fields:
idtitlecontentcreatedAtupdatedAt
- Route:
-
PUT Update Blog
- Route:
/api/blog/{blogId} - Updates a blog and returns the updated blog with the following fields:
idtitlecontentcreatedAtupdatedAt
- Route:
-
DELETE Delete Blog
- Route:
/api/blog/{blogId} - Deletes a blog and returns the deleted blog with the following fields:
idtitlecontentcreatedAtupdatedAt
- Route:
Note: All of these routes require a JWT token in the request header, which is provided upon signing in.
Follow these steps to set up and run the backend API:
- Clone the Git repository.
- Create a
.envfile and edit the following PostgreSQL and JWT_SECRET configurations:DB_HOST=[Hostname]DB_PORT=5432DB_PASSWORD=[Password]DB_NAME=blogJWT_SECRET=randomSecretKey
- Download and install Node.js.
- Run
npm installin the project directory using the command line. - Start the server by running
npm startin the project directory using the command line. - Create a user by using the provided user routes.
- Sign in to obtain an authentication token.
- Use the blog routes with the obtained token in the request header for authentication.