Skip to content

mhadikz/Blog-Node.js-Express-MongoDB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blog APIs

The project has created basic and common APIs that a blog needs them.

API Reference

Post register attributes

  POST /api/v1/auth/register
Body Type Description
username string Required. Your username.
password string Required. Your password.
email string Required. Your email.
name string Optional. Your name for using on post details.

Post login attributes

  POST /api/v1/auth/login
Body Type Description
username string Required. Your username.
password string Required. Your password.

You will get a JWT token in response that will be used for authorization on following APIs.

Post a new content

  POST /api/v1/content/add-post
Body Type Description
title string Required. Title of the post.
body string Required. Body of the post.
tags array Required. Delected tags for the post.
categories array Required. Selected categories for the post.
Headers Value Description
Authorization JWT ${TOKEN} Required. The token that has been generated on the login step.

Get all posts

  GET /api/v1/content/posts

This endpoint will return all created blog posts

  GET /api/v1/content/post/${id}
Parameter Type Description
id string Required. The id of one of the exists posts.

Update a post

  PUT /api/v1/content/post/${id}
Parameter Type Description
id string Required. The id of one post.
Headers Value Description
Authorization JWT ${TOKEN} Required. The token that has been generated on the login step.

Delete a post

  DELETE /api/v1/content/post/${id}
Parameter Type Description
id string Required. The id of one post.
Headers Value Description
Authorization JWT ${TOKEN} Required. The token that has been generated on the login step.

Environment Variables

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

DB_ADDRESS

DB_USER

DB_PASS

PORT

JWT_PRIVATE_KEY

Run Locally

Clone the project

  git clone https://github.com/mhadikz/Blog-Node.js-Express-MongoDB

Go to the project directory

  cd Blog-Node.js-Express-MongoDB

Install dependencies

  npm install

Start the server

  npm start

Tech Stack

Server: Node, Express, MongoDB, Docker, Mongoose, JsonWebToken