-Review, Research, and Discussion
- Name 3 real world use cases where you’d want to change the request with custom middleware
- Authentication (Auth middleware)
- Error Handling (Error Handing Middleware)
- Logging-in (Logging Middleware)
- True or false: The route handler is middleware?
- The route handler is middleware.
- In what ways can a middleware function end the process and send data to the browser?
- Sending an error message by passing a string to next
("string")
- without writing
next()
.
At what point in the request lifecycle can you “inject” middleware?
- Between in the middle of the request and the response .
- When a server tries to send several responses for one request.
Vocabulary Terms
Middleware :
- are functions that have access to the request object (req), the response object (res), and the next middleware function in the application’s request-response cycle.
Request Object :
- Request is used to describe an request to a server.
Response Object :
- The res object represents the HTTP response that an Express app sends when it gets an HTTP request.
Application Middleware :
- a middleware that works on application level like authentication .
Routing Middleware :
- a middleware that works on router level.
Test Driven Development :
- is the act of first deciding what you want your program to do (the specifications), formulating a failing test, then writing the code to make that test pass.
Behavioral Testing :
- focused on the behaviour of users rather than the technical functions of the software.
Classes
- Functions in JavaScript that create a template code that makes the code more readable and easy to use.
- Classes must be declared before used.
Express Routing
- refers to how an application’s endpoints (URIs) respond to client requests.
- Routes is declered as follow:
app.HTTP_method(Path, handler Function);
- To specify a middleware as the callback function we use :
app.use()
*************************