reading-notes

this repo will contain my reading during the course .

View project on GitHub

Express REST API

img

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()

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

when sending a request or a request parameter by the client side will inject the middleware so Middleware is usually injected during a req and before a response cycle, this means that middleware is a dependency and the req and res cycle depend on the middleware to take place.

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

means that you’re already in the Body or Finished state, but some function tried to set a header, like callbacks invoked twice for example.

Document the following Vocabulary Terms

Middleware: functions that have access to the request object (req), the response object (res), that can Execute any code. Make changes to the request and the response objects.

img

Request Object:object represents the HTTP request and has properties for the request query string, parameters, body, HTTP headers, and so on.(req.body)

Response Object: The res object represents the HTTP response that an Express app sends when it gets an HTTP request. (rs.status)

Application Middleware:software that provides common services and capabilities to applications

Routing Middleware: middleware function that we can define it and invoke globaly by app.use

Test Driven Development:TDD is 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 software again all test cases.

Behavioral Testing: A type of testing using the external behavior of the program, which is also known as black box testing

Preview

Which 3 things had you heard about previously and now have better clarity on?

SOAP, TDD, Request Object

Which 3 things are you hoping to learn more about in the upcoming lecture/demo?

SOAP and TDD and REST

What are you most excited about trying to implement or see how it works?

I think in general I’m excited just to manipulate code and to make it so I can refactor to a point of clarity that is easy to read and easy to repeat.

Resuorses :