Skip to content

OgeHub/blog

Repository files navigation

NodeJS API using TypeScript

Introduction: This is my first NodeJS API with TypeScript. Thanks to Rettson for his tutorial video on using the NodeJS API with TypeScript, which majorly guided me to accomplish this. Click here for the detailed API documentation on Postman.

Description: With this API, you can register as a user and make a post. Below are the routes in this API.

Base URL

Local: Base_URL = http://localhost:3000/api
Live: Base_URL = https://my-nodejs-typescript.onrender.com/api

Routes

Register:

POST /users/register
Host: Base_URL
Content-type: application/json
  • Request body:
{
    "username": "testUser",
    "name": "Test User",
    "email": "[email protected]",
    "password": "testing12"
}

Verify Email:

PATCH /users/verify_email/:token
Host: Base_URL

Content-Type: application/json

Login with username:

POST /users/login_with_username
Host: Base_URL
Content-Type: application/json
  • Request body:
{
    "username": "testUser",
    "password": "testing12"
}

Login with Email:

POST /users/login_with_email
Host: Base_URL
Content-Type: application/json
  • Request body:
{
    "email": "[email protected]",
    "password": "testing12"
}

Forgot password:

PATCH /users/forgot_password
Host: Base_URL
Content-Type: application/json
  • Request body:
{
    "email": "[email protected]"
}

Reset password:

PATCH /users/reset_password/:token
Host: Base_URL
Content-Type: application/json
  • Request body:
{
    "password": "testing12"
}

Get all users:

GET /users
Host: Base_URL
Accept: application/json
Authorization: Bearer accessToken(from response of register or login)

Get a user details:

GET /users/:id
Host: Base_URL
Content-Type: application/json
Authorization: Bearer accessToken(from response of register or login)

Edit user details:

PATCH /users/:id
Host: Base_URL
Content-Type: application/json
Authorization: Bearer accessToken(from response of register or login)
  • Request body:
{
    "username": "editUser",
    "name": "Edit User"
}

Create a post:

POST /posts
Host: Base_URL
Content-Type: application/json
Authorization: Bearer accessToken(from response of register or login)
  • Request body:
{
    "title": "Testing Post",
    "body": "This is a testing post"
}

Get all posts:

GET /posts
Host: Base_URL
Content-Type: application/json
Authorization: Bearer accessToken(from response of register or login)

Get a post:

GET /posts/:id
Host: Base_URL
Content-Type: application/json
Authorization: Bearer accessToken(from response of register or login)

Delete a post:

DELETE /posts/:id
Host: Base_URL
Content-Type: application/json
Authorization: Bearer accessToken(from response of register or login)

Edit a post:

PATCH /posts/:id
Host: Base_URL
Content-Type: application/json
Authorization: Bearer accessToken(from response of register or login)
  • Request body:
{
    "title": "Editing Post",
    "body": "This is editing post"
}

Technologies

NodeJS TypeScript Express MongoDB

Updates coming soon:

  1. Live URL
  2. Edit user details
  3. Delete and edit post(by user that created it)
  4. Verify email
  5. Reset password
  6. Logout
  7. Sorting, limit and pagination(for get all users and get all posts)

About

A NodeJS + TypeScript API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published