Express REST API
1. Name 3 real world use cases where you’d want to change the request with custom middleware
-
In one scenario you can identify the currently logged in user, so using the custom middleware fetches the user through a set of authentication steps.
-
A second example is changing the functionality on your response object, such as creating a new header. I could foresee a company doing that to advertise a sale of a product.
-
Building on the fact that a user logs in, the custom middleware can be uses to also validate a users data. The users information and credentials could be stored in a database to verify the information is correct.
in other words :
-
Application level middleware
-
Built in middleware
-
Error handling middleware
2. True or false: The route handler is middleware?
True, route handling is a part of middleware functionality. The exception is route handling may invoke the next function parameter to pass control onto the middleware function within the stack.
3. In what ways can a middleware function end the process and send data to the browser?
-
res.send()
-
res.redirect()
-
res.render()
-
res.sendFile()
-
res.download()