- The controller layer is where we handle the incoming HTTP requests and outgoing responses.
- This layer uses the services from the service layer.
- After completing the job, this layer constructs responses with appropriate status codes and data.
- This layer can take help from middlewares for tasks like authenticating client's request, securing the routes, parsing request body, etc. Middlewares are the extra layer of functions that have access to request and response objects from the HTTP calls.
Navigate to the
srcfolder and create a
controllers.jsfile inside both the
The project structure will look something like this:
We will import the
authorservices and use appropriate functions to handle the requested task.
We will extract the request body from the client.
We will also extract the parameters from the URL, if any.
After completing the requested task, we will usually respond with processed data with a status code.
We will repeat the same steps with
- We have created controllers for the
- In the next part, we will specify routes to our controller layer.
- The link to the project repo is available here.