Express Flashcards
What is
Express
Express is a web framework built on top of Node.
What does Express provide?
Ways to:
* Write handlers for HTTP requests (routes)
* Integrate with view-rendering engines
* Add “middleware” within the request handling pipeline.
What are middleware functions used for?
Middleware functions are used to pre-process incoming requests and outgoing responses.
What are middleware functions defined as?
Middleware functions are defined as functions that take request
, response
, and a next
handler.
What is
Axios
A JavaScript library that is used to generate HTTP requests and receive/parse the responses from the Express web server.
What kind of interface does Axios use?
Axios uses a promise-based interface.
* Every Axios request must return a promise.
* The promise is resolved when the response arrives.
* Use then
or async/await
to handle Axios requests.
The intended Axios API is ?-based.
The intended Axios API is constructor-based.
In Express,
What does a route define?
A route defines the type of HTTP message that the server is waiting for.
In Express,
What does a route contain?
A route contains a callback function that controls how the server responds when a message arrives (that matches one of the defined routes).
What are the
2 Primary Components of a Route
- Method
- Path
Route Definition: HTTP Method
The HTTP Method defines the type of request being sent to a server and how the server should handle it.
It determines what action is performed on the route.
Examples: GET
, POST
, HEAD
, PUT
, DELETE
, etc.
Route Definition: Path
The Path is the string or pattern that defines the URL to match.
It is the first parameter passed to a route method.
Examples: String route, String pattern route, Regex route
Route Definition: Handlers
The Handler is a callback function that is triggered when an HTTP request that matches the route arrives at the web server.
What is an
Instance of Express
app: app.Method(PATH, HANDLER)