Skip to content

jhhornn/nest-post-api

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Description

Nest framework TypeScript starter repository.

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

Test

# unit tests
$ npm run test

Seed

# seed
$ npm run seed

Env

change .env.example.dev to .env.stage.dev and update the values in it.

Doc

http://localhost:3000/api-doc

Routes

root url - http://localhost:3000
root route - /api/v1/

API Endpoints - Posts

Endpoint Method Description
posts/ GET Get posts(include filters)
posts/:id GET Get a post
posts/ POST Create a posts
posts/ DELETE Delete a post
posts/:id PATCH Update a post

API Endpoints - Auth

Endpoint Method Description
auth/signup/ POST Sign up
auth/signin/ POST Sign in
auth/forgot-password/ POST Request token to change password
auth/reset-password/ POST Reset Password

Entities

User

field data_type constraints
id ObjectId autogenerated
email string required and unique
password string required
resetToken string default=''
posts [ ObjectId ] autogenerated on creation

Posts

field data_type constraints
id ObjectId autogenerated
title string required
description string required
body string required
user ObjectId autogenerated on creation

Description of Flow

  1. Client sends a request to the API server
  2. API server checks if the request requires authentication
  3. If authentication is required, API server checks if the client has a valid token
  4. If the client has a valid token, API server proceeds with the request
  5. If the client does not have a valid token, API server sends a 401 Unauthorized response
  6. If authentication is not required, API server proceeds with the request
  7. API server processes the request based on the HTTP method (GET, POST, DELETE, or PUT)
  8. If the request is GET, API server retrieves the resource and sends it back to the client
  9. If the request is POST, API server creates a new resource and sends a 201 Created response with the URI of the new resource
  10. If the request is DELETE, API server deletes the resource and sends a 204 No Content response
  11. If the request is PUT, API server updates the resource and sends a 200 OK response with the updated resource

Note: The client obtains a valid token through an authentication process and sends the token with each request in the Authorization header. The API server validates the token using a token validation service or a similar mechanism.

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

About

A CRUD posts API built using NestJS and TypeORM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published