Skip to content

cheatsnake/blog-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

65 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฐ Blog API

Simple API for building cool blogs
Crafted using Nest.js + MongoDB

๐Ÿ” Overview

This API provides the ability to create simple blogs with markdown markup based on an already created system of posts and comments. For convenient blogging, there is an administrator authorization service with a set of secure routes. The comments service does not require registration, but all comments can be verified by administrators.

๐Ÿš€ Launch server

  1. Clone this repository
  2. Create .env file with connection URI and JWT secret key
DATABASE_URI=mongodb://mongodb0.example.com:27017
JWT_SECRET=PasteYourJwtSecret
  1. Install all packages
npm install
  1. Run server for development/production
npm run start:dev
npm run start

๐Ÿณ Launch using Docker

  1. Build docker image
docker build . -t blog-api
  1. Launch containter
docker run -p 3000:3000 --env-file .env --name server blog-api

๐Ÿ“„ API usage

You can use a specially prepared collection of endpoints for Insomnia client. For this just import ./blog-api.insomnia.json file.

๐Ÿ” Auth for admins

Method URI Body (JSON) Action
POST /api/auth/register {
โ€ƒ "email": "example@mail.com",
โ€ƒ "password": "example"
}
Registration for admins
POST /api/auth/login {
โ€ƒ "email": "example@mail.com",
โ€ƒ "password": "example"
}
Login for admins

๐Ÿ“ฎ Post service

Method URI Body (JSON) Action
POST /api/post {
โ€ƒ "category": "category",
โ€ƒ "title": "title",
โ€ƒ "image": "test.png",
โ€ƒ "tags": ["one", "two"],
โ€ƒ "content": "Hello World!"
}
Create post (For admins)
GET /api/post/id none Find post by id
GET /api/post/withComments/id none Find post by id with comments
POST /api/post/find/id {
โ€ƒ "category": "category",
โ€ƒ "limit": 100
}
Find posts by category
PATCH /api/post/id {
โ€ƒ "category": "category",
โ€ƒ "title": "title",
โ€ƒ "image": "test.png",
โ€ƒ "tags": ["one", "two"],
โ€ƒ "content": "Hello World!"
}
Update post by id (For admins)
DELETE /api/post/id none Delete post by id (For admins)

๐ŸŽค Comment service

Method URI Body (JSON) Action
POST /api/comment {
โ€ƒ "author": "Author",
โ€ƒ "email": "test@mail.com",
โ€ƒ "content": "Hello World!",
โ€ƒ "postId": id
}
Create comment for post
GET /api/comment/id none Find comment by id
GET /api/comment/byPost/id none Find comment by post id
GET /api/comment/verified/id none Verified comment by id (For admins)
DELETE /api/comment/id none Delete comment by id (For admins)