Express REST API
- Name 3 real world use cases where you’d want to change the request with custom middleware
- printing a message
- trigger an error handler
- request timestamp
-
True or false: The route handler is middleware?
- false, a middleware function requires
nextargument to proceed to next
- false, a middleware function requires
-
In what ways can a middleware function end the process and send data to the browser?
response.end()response.status(number).send('message')
-
At what point in the request lifecycle can you “inject” middleware?
- after HTTP method and before the Path
-
What can cause express to error with “Request headers sent twice, cannot start a second response”
- callback has been called twice
- another function trying to set a header or status code
Terms
-
Middleware: functions that that execute during the lifecycle of a request to the Express server
-
Request Object: the main entry point for an application to issue a request to the Library
-
Response Object: send data from the server to the client through an HTTP request
-
Application Middleware: send requests to the server
-
Routing Middleware: bound to an instance of
express.Router()