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.
Local: Base_URL
= http://localhost:3000/api
Live: Base_URL
= https://my-nodejs-typescript.onrender.com/api
Register:
POST /users/register
Host: Base_URL
Content-type: application/json
- Request body:
{
"username": "testUser",
"name": "Test User",
"email": "test@user.api",
"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": "test@user.api",
"password": "testing12"
}
Forgot password:
PATCH /users/forgot_password
Host: Base_URL
Content-Type: application/json
- Request body:
{
"email": "test@user.api"
}
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"
}
NodeJS TypeScript Express MongoDB
Updates coming soon:
Live URLEdit user detailsDelete and edit post(by user that created it)Verify emailReset password- Logout
- Sorting, limit and pagination(for get all users and get all posts)