Skip to content

API Request Flow

ankitpws edited this page Sep 21, 2022 · 1 revision

In Elevate service data is transferred via API contracts will have to look at different levels of API validation and retrieval of data from DB.

Client

The client is also known as a Front-end Application that will make calls to backend services and receive various responses like success and failure.

Authorization

While making an API call, the user has to pass data like an access token which will have the user's email id and type of user. An access token is valid only for 24 hours once it expires it has to be regenerated using a refresh token. Once an access token is decoded and has valid info then it will pass the request to pagination if the API call wants paginated data. Once it's completed the request will be transferred to the API endpoint. This authorization will be acting as middleware. Files for token authorization will be in the middleware/ folder.

Router

In the API endpoint info like version, controller, methods, and ids will be extracted and requests will be sent to a particular controller after validation. from router/index.js request will go to the validator folder of a particular controller. For accessing a validator folder request will be sent to validator middleware it will be in the middleware folder.

Validator

The validator will be acting as middleware and responsible for validating incoming request data eg email id, session name, etc. once incoming data is validated it will be transferred to a specific controller. Validators are placed in a validator folder and the name of a file will be the controller name.

Controller

All the controllers are placed in the src/controller/ folder. After validating the request from validation, it reaches to controller file and is responsible for sending the req to the service file where it will be processed and the response will be returned to the controller.

Service

Once the controller files send a request to the services file it will look for what business logic has to be performed whether it is getting data from DB or doing some calculation it will be written over here. All the service files are written in the src/service/helper/ folder.

Clone this wiki locally