Recall & Review
beginner
What are route parameters in Express?
Route parameters are parts of the URL that act as placeholders for values. They let you capture values from the URL and use them in your code.Click to reveal answer
beginner
How do you define a route parameter in an Express route?
You define a route parameter by adding a colon (:) before a name in the route path, like '/user/:id'. This means 'id' is a parameter you can access.
Click to reveal answer
beginner
How do you access route parameters inside an Express route handler?
You access route parameters using 'req.params'. For example, if your route is '/user/:id', you get the id with 'req.params.id'.
Click to reveal answer
intermediate
What happens if you define multiple route parameters in Express?
You can define multiple parameters like '/user/:userId/book/:bookId'. Each parameter is available in 'req.params' by its name, e.g., 'req.params.userId' and 'req.params.bookId'.
Click to reveal answer
intermediate
Can route parameters be optional in Express? How?
Yes, by adding a question mark (?) after the parameter name, like '/user/:id?'. This means the parameter is optional and the route matches with or without it.
Click to reveal answer
How do you define a route parameter named 'postId' in Express?
✗ Incorrect
Route parameters are defined with a colon before the name, like '/post/:postId'.
Where do you find the value of a route parameter inside an Express route handler?
✗ Incorrect
Route parameters are stored in 'req.params' as key-value pairs.
What does the route '/user/:id?' mean in Express?
✗ Incorrect
Adding '?' after a parameter name makes it optional.
If you have a route '/product/:category/:id', how do you access the 'category' parameter?
✗ Incorrect
Route parameters are accessed via 'req.params' by their names.
Which of these is NOT a valid route parameter definition in Express?
✗ Incorrect
Without a colon, 'itemId' is treated as a fixed path segment, not a parameter.
Explain how to create and use route parameters in Express routes.
Think about how URLs can carry data like user IDs.
You got /3 concepts.
Describe how to make a route parameter optional and why you might want to do that.
Optional means the URL can have that part or skip it.
You got /3 concepts.