Reading notes for class 3 of 401

Express REST API

Name 3 real world use cases where you’d want to change the request with custom middleware
  • printing a message
  • timestamping
  • validating and logging data
True or false: The route handler is middleware?

False.

In what ways can a middleware function end the process and send data to the browser?

Don’t call next() in the middleware, instead use res.end, res.send, res.render.

At what point in the request lifecycle can you “inject” middleware?

Between the HTTP method being used and the path it is going to.

What can cause express to error with “Request headers sent twice, cannot start a second response”

Callback being called twice, or another function trying to set a status code.

Vocab

Middleware

  • Functions that access two applications

Request Object

  • The main entry point for an HTTP Request, has properties for the query string, parameters, body, HTTP headers…

Response Object

  • HTTP response that an application sends back after recieving a request

Application Middleware

  • Middleware that sends requests to the server

Routing Middleware

  • Same as application middleware except it is bound to an instance of express.Router();

Test Driven Development

  • Validates code before software is fully developed

Behavioral Testing

  • Testing of outputs regardless of how the software actually arrives to it