Personal Project

RESTful API

Summary

This is a RESTful API built with Express and TypeScript, featuring authentication, product, category, payment and image routes.

Tags:

APIBackend

Tools

Express.JSNode.JSTypeScriptMongoDBCloudinary

Authentication

User authentication is done through using JSON Web Tokens (JWTs).

Register

Method:
POST
Requisites:
  • name, email, password in req.body
Query URL:

https://restful-api-lcl.up.railway.app/api/user/register

Resolve:

Send account activation email to use.

Activation

Method:
POST
Requisites:
  • activation_token in req.body
Query URL:

https://restful-api-lcl.up.railway.app/api/user/activation

Resolve:

Notification of activation content.

Login

Method:
POST
Requisites:
  • email, password in req.body
Query URL:

https://restful-api-lcl.up.railway.app/api/user/login

Resolve:

Set refresh token and access token for Cookies client

Refresh

Method:
POST
Requisites:
  • Token must be valid.
  • User must be authenticated
Query URL:

https://restful-api-lcl.up.railway.app/api/user/refresh

Resolve:

Set again access token for Cookies client

Logout

Method:
POST
Requisites:
  • Token must be valid.
  • User must be authenticated
Query URL:

https://restful-api-lcl.up.railway.app/api/user/logout

Resolve:

Remove access token and refresh token from Cookies client

Logout All

Method:
POST
Requisites:
  • Token must be valid.
  • User must be authenticated
Query URL:

https://restful-api-lcl.up.railway.app/api/user/logout-all

Resolve:

Logout a user all devices.

Forgot

Method:
POST
Requisites:
  • email in req.body
Query URL:

https://restful-api-lcl.up.railway.app/api/user/forgot

Resolve:

Send email reset password to email.

User

User api

User information

Method:
GET
Requisites:
  • Token must be valid.
  • User must be authenticated.
Query URL:

https://restful-api-lcl.up.railway.app/api/user/me

Resolve:

Json user information is retrieved from token.

Update

Method:
PATCH
Requisites:
  • Token must be valid.
  • User must be authenticated.
Query URL:

https://restful-api-lcl.up.railway.app/api/user/update

Resolve:

Update the information of a specific user..

Add to cart

Method:
PATCH
Requisites:
  • Token must be valid.
  • User must be authenticated.
  • Product must not be previously stored.
Query URL:

https://restful-api-lcl.up.railway.app/api/user/add_cart

Resolve:

Notification of activation content.

Add to wish list

Method:
PATCH
Requisites:
  • Token must be valid.
  • User must be authenticated.
  • Product must not be previously stored.
Query URL:

https://restful-api-lcl.up.railway.app/api/user/wish_list

Resolve:

Notification of activation content.

Categories

Categories API.

Get categories

Method:
GET
Requisites:
  • End point without prerequisites.
Query URL:

https://restful-api-lcl.up.railway.app/api/categories

Resolve:

Returns a list of all categories.

Create category

Method:
POST
Requisites:
  • Token must be valid
  • User must be authenticated.
  • Only users with role = 1 (Administrator) can make this request.
Query URL:

https://restful-api-lcl.up.railway.app/api/categories

Resolve:

Returns a message with the ID of the created category.

Get specific category

Method:
GET
Requisites:
  • End point without prerequisites.
Query URL:

https://restful-api-lcl.up.railway.app/api/categories/:id

Resolve:

Returns an array with the specified category.

Update / Delete category

Method:
PUTDELETE
Requisites:
  • Token must be valid
  • User must be authenticated.
  • Only users with role = 1 (Administrator) can make this request.
Query URL:

https://restful-api-lcl.up.railway.app/api/categories/:id

Resolve:

Delete, or update the information of the specific category.

Products

Products API.

Get products

Method:
GET
Requisites:
  • End point without prerequisites.
Query URL:

https://restful-api-lcl.up.railway.app/api/products

Resolve:

Returns an array with all the categories stored in the database.

Create product

Method:
POST
Requisites:
  • Token must be valid
  • User must be authenticated.
  • Only users with role = 1 (Administrator) can make this request.
Query URL:

https://restful-api-lcl.up.railway.app/api/product

Resolve:

Returns a message with the ID of the product created.

Get specific product

Method:
GET
Requisites:
  • End point without prerequisites.
Query URL:

https://restful-api-lcl.up.railway.app/api/product/:id

Resolve:

Update / Delete product

Method:
PUTDELETE
Requisites:
  • Token must be valid
  • User must be authenticated.
  • Only users with role = 1 (Administrator) can make this request.
Query URL:

https://restful-api-lcl.up.railway.app/api/product/:id

Resolve:

Payments

Payments API.

Get payments

Method:
GET
Requisites:
  • Token must be valid
  • User must be authenticated.
  • Only users with role = 1 (Administrator) can make this request.
Query URL:

https://restful-api-lcl.up.railway.app/api/payments

Resolve:

Returns the public_id and public_url of the image hosted on Cloudinary.

Create payment

Method:
POST
Requisites:
  • Token must be valid
  • User must be authenticated.
Query URL:

https://restful-api-lcl.up.railway.app/api/payments

Resolve:

Delete the cloudinary image.

Images

Images API.

Upload image

Method:
POST
Requisites:
  • Token must be valid
  • User must be authenticated.
  • Only users with role = 1 (Administrator) can make this request.
Query URL:

https://restful-api-lcl.up.railway.app/api/image/upload

Resolve:

Returns the public_id and public_url of the image hosted on Cloudinary.

Delete Image

Method:
POST
Requisites:
  • Token must be valid
  • User must be authenticated.
  • Only users with role = 1 (Administrator) can make this request.
Query URL:

https://restful-api-lcl.up.railway.app/api/image/destroy

Resolve:

Delete the cloudinary image.

No Rights Reserved@lecongly• ©2023