reading-notes

Reading notes for Code Fellows!


Project maintained by William-Moreno Hosted on GitHub Pages — Theme by mattgraham

Express REST API


3 Real World Use Cases to Change the Request with Custom Middleware

True or False: The Route Handler is Middleware?

After researching numerous sources including but not limited to Express.docs, GitHub, StackOverflow MDN Web Docs, there appears to be plenty debate over whether route handlers are middleware or not. The debates touch on topics such as the absence of the next argument, the handlers association with HTTP request verbs, whether middleware delivers a response to a request and other criteria. In my opinion, they are not middleware, they are ‘handlers’ (callback functions for routes/requests), but I can not support that interpretation with any hard evidence.

In What Ways Can a Middleware Function End the Process and Send Data to the Browser?

At What Point in the Request Lifecycle Can Middleware be “Injected”?

Middleware can be ‘injected’ anytime after the request has been made and before a response has been returned. During the time that the request is “in the tunnel” between request and response.

What Can Cause Express to Error with “Request headers sent twice, cannot start a second response”?

This means that for a given client request the server previously sent a response back to the client and now is unexpectedly trying to send another response to the same request. Understanding Node Error [ERR_HTTP_HEADERS_SENT] by Prosper Opara

Vocabulary Terms

| Vocabulary Term | Definition | | — | — | | Middleware | Middleware are functions executed in the middle, after the incoming request then produces an output A Simple Explanation of Express Middleware | | Request Object | The request object represents the HTTP request and has properties for the request string, parameters, body HTTP headers, and more TutorialsPoint | | Response Object | The response object is data returned from the server to a client following an HTTP request, and has many properties much like a request object | Application Middleware | Middleware that is bound to an instance of the app object such as app.use() and app.get() and other HTTP verbs that facilitates functionality of the application | | Routing Middleware | Router-level middleware works in the same way as application-level middleware, except it is bound to an instance of express.Router() Expressjs | | Test Driven Development | *A software development process relying on software requirements being converted to test cases before software is fully developed, and tracking all software development by repeatedly testing the software against all test cases. This is opposed to software being developed first and test cases created later. Wikipedia | | Behavorial Testing | An Agile software development process that encourages collaboration among developers, QA and non-technical or business participants in a software project. It encourages teams to use conversation and concrete examples to formalize a shared understanding of how the application should behave. Wikipedia |

3 Things I Had Previously Heard of and Now Have Better Clarity On

  1. Subclasses and extending not only ES6 syntax classes but also traditional function-based “classes”
  2. Route paths used with request methods not only define endpoints, but also can be comprised of strings, string-patterns or even regular expressions
  3. Hoisting affects varying kinds of declarations differently

3 Things I Am Hoping to Learn More About in the Upcoming Lecture

  1. Writing error-handling modules correctly
  2. express.Router()
  3. Hoisting, as it relates to class declarations

I Am Most Excited About Trying to Implement or See How These Work:

Back to Main