HTTP / Express.js Flashcards

1
Q

What is a client?

A

A device that requests services from a server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a server?

A

A device that provides services to clients.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

The GET method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What three things are on the start-line of an HTTP request message?

A

HTTP method, the request target, and the HTTP version.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What three things are on the start-line of an HTTP response message?

A

HTTP version, status code, and status text.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are HTTP headers?

A

Key value pairs that allow the client and server to pass additional information in an HTTP request or response.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Where would you go if you wanted to learn more about a specific HTTP Header?

A

MDN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is a body required for a valid HTTP request or response message?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you add express to your package dependencies?

A

npm install express

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What Express application method starts the server and binds it to a network PORT?

A

express.listen(portNumber, callBack);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you mount a middleware with an Express application?

A

express.use((req, res, next) => {
code block here
})

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

req, res, and next

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?

A

application/json

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the express.json() middleware do and when would you need it?

A

The middleware function parses posted JSON strings from requests and adds them as the req.body object. You would need it whenever the server deals with JSON input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the significance of an HTTP request’s method?

A

The significance is for humans, servers can technically be programmed to respond in any way possible to HTTP request methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does express.static() return?

A

The serveStatic middleware function.

17
Q

What is the local __dirname variable in a Node.js module?

A

A string that lists the absolute file path of the module the directory is in.

18
Q

What does the join() method of Node’s path module do?

A

Joins the arguments into a path.

19
Q

What does fetch() return?

A

A promise for a response object.

20
Q

What is the default request method used by fetch()?

A

GET

21
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

Specify method in the init object argument: fetch(url, { method: ‘METHOD’ })