0
0
Expressframework~5 mins

req.method and req.url in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does req.method represent in Express?

req.method is a string that shows the HTTP method used in the request, like GET, POST, PUT, or DELETE.

Click to reveal answer
beginner
What information does req.url provide in an Express request?

req.url gives the path and query string part of the URL the client requested, for example, /home?user=123.

Click to reveal answer
intermediate
How can req.method and req.url be used together in Express?

You can check req.method and req.url to decide how to respond, like handling GET requests to /about differently from POST requests to /submit.

Click to reveal answer
beginner
Example: What will req.method and req.url be if a user visits POST /login?

req.method will be "POST" and req.url will be "/login".

Click to reveal answer
beginner
Why is it useful to check req.method in your Express app?

Because it helps your app know what the client wants to do, like get data, send data, update, or delete something, so you can respond correctly.

Click to reveal answer
What does req.method contain in an Express request?
AThe response status code
BThe full URL including domain
CThe request headers
DThe HTTP method like GET or POST
If a user visits http://example.com/products?item=5, what will req.url be?
A/products?item=5
Bhttp://example.com/products?item=5
C/products
Ditem=5
Which of these is true about req.method and req.url?
ABoth contain the full URL
B<code>req.method</code> is the URL path, <code>req.url</code> is the HTTP method
C<code>req.method</code> is the HTTP method, <code>req.url</code> is the URL path and query
DBoth contain HTTP headers
Why might you check req.method in your Express route handler?
ATo know what kind of request the client sent
BTo get the client's IP address
CTo read cookies
DTo set response headers
What will req.url be if the user requests GET /search?q=books?
AGET
B/search?q=books
C/search
Dbooks
Explain what req.method and req.url represent in an Express request and how you might use them.
Think about how your app knows what the client wants and where.
You got /3 concepts.
    Describe a simple example where checking req.method and req.url helps your Express app respond differently.
    Imagine a website with a home page and a form submission.
    You got /4 concepts.