- Name 3 real world use cases where you’d want to change the request with custom middleware source
- user authentication
- improving database query efficiency
- caching
- True or false: The route handler is middleware?
- True
- In what ways can a middleware function end the process and send data to the browser?
- executing response.send()
- At what point in the request lifecycle can you “inject” middleware?
- after the request has been made, but prior to the response being sent back
- What can cause express to error with “Request headers sent twice, cannot start a second response”
- If you send a response and try to execute code that sends another response
- Middleware - functions that have access to the request object and the response object as well as the next function which can execute code, make changes to the request or reponse objects, end the WRRC, and call the next middleware in the stack. source
- Request Object - represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on. source
- Response Object - epresents the HTTP response that an Express app sends when it gets an HTTP request. source
- Application Middleware - middleware executed on the app object source
- Routing Middleware - functions the same as app middleware, but executed on the express.Router() instance source
- Test Driven Development (TDD) - can be boiled down to all production code is written in response to a test case source
- Think about the behaviors that your implementation requires. Select a behavior to implement.
- Write a test that validates the behavior. The test case must fail.
- Add only enough code to make the new test case and all previous test cases pass.
- Refactor the code to eliminate duplicate code, if necessary.
- Select the next requirement and repeat steps 1 - 4.
- Behavioral Testing - also known as Behavior Driven Development (BDD) is a branch of TDD that uses human-readable descriptions of software user requirements as the basis for software tests. source
- Which 3 things had you heard about previously and now have better clarity on?
- Routing Middleware, Request Object, Response Object
- Which 3 things are you hoping to learn more about in the upcoming lecture/demo?
- TDD, BDD, real cases for middleware modifying requests
- What are you most excited about trying to implement or see how it works?
- routing middleware