0
0
Expressframework~5 mins

req.headers for HTTP headers in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is req.headers in Express?

req.headers is an object in Express that contains all the HTTP headers sent by the client in a request.

Click to reveal answer
beginner
How do you access the 'Content-Type' header from req.headers?

You can access it using req.headers['content-type']. Header names are case-insensitive but usually lowercase in req.headers.

Click to reveal answer
beginner
True or False: req.headers keys are case-sensitive.

False. HTTP headers are case-insensitive, and Express normalizes them to lowercase in req.headers.

Click to reveal answer
intermediate
Why might you check req.headers['authorization'] in an Express app?

To get the authorization token or credentials sent by the client, often used for checking if the user is allowed to access a resource.

Click to reveal answer
beginner
What happens if you try to access a header that was not sent in the request?

You get undefined because that header does not exist in req.headers.

Click to reveal answer
What type of data structure is req.headers in Express?
AAn object with header names as keys
BAn array of header strings
CA string containing all headers
DA function to get headers
How are header names stored in req.headers?
AUppercase
BMixed case as sent by client
CLowercase
DRandom case
If a client sends no 'Authorization' header, what is req.headers['authorization']?
AAn empty string
Bundefined
CThrows an error
Dnull
Which header would you check to find the type of data sent in the request body?
Acontent-length
Baccept
Cauthorization
Dcontent-type
Why is it important to check req.headers in an Express app?
ATo read client data like tokens or content type
BTo send headers to the client
CTo modify the request URL
DTo close the connection
Explain what req.headers is and how you use it in an Express app.
Think about how the server reads info sent by the browser or client.
You got /4 concepts.
    Describe a real-life example where checking req.headers is useful in a web app.
    Imagine you want to know who is sending the request or what kind of data they sent.
    You got /3 concepts.