Challenge - 5 Problems
Route Parameters Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output when accessing a route with parameters?
Consider this NestJS controller method:
What will be the response body when a client requests
@Get('user/:id')
getUser(@Param('id') id: string) {
return `User ID is ${id}`;
}What will be the response body when a client requests
/user/42?Attempts:
2 left
💡 Hint
Route parameters are extracted from the URL and passed to the method.
✗ Incorrect
The @Param('id') decorator extracts the 'id' part from the URL path. So when the URL is /user/42, id equals '42'. The method returns the string with that value.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a route with two parameters?
You want to create a GET route in NestJS that matches URLs like
Which method signature is correct?
/order/123/item/456 and extracts both orderId and itemId as parameters.Which method signature is correct?
Attempts:
2 left
💡 Hint
Each parameter must be decorated separately or use @Param() to get all.
✗ Incorrect
Option D correctly uses @Param('orderId') and @Param('itemId') to extract each parameter individually. Option D is invalid because @Param() returns an object but the type annotation is incorrect. Option D uses invalid syntax for @Param. Option D misses @Param on itemId.
🔧 Debug
advanced2:00remaining
Why does this route parameter extraction fail?
Given this controller method:
What error or issue will occur when calling
@Get('product/:id')
getProduct(@Param() id: string) {
return `Product ID: ${id}`;
}What error or issue will occur when calling
/product/10?Attempts:
2 left
💡 Hint
Check what @Param() returns when no argument is given.
✗ Incorrect
@Param() without an argument returns an object with all parameters. Assigning it to a string variable causes a type mismatch. Using it as a string causes a TypeError.
🧠 Conceptual
advanced2:00remaining
How does NestJS handle optional route parameters?
You want to define a route where the parameter
Which route path correctly supports this?
category is optional, matching both /products and /products/electronics.Which route path correctly supports this?
Attempts:
2 left
💡 Hint
Optional parameters use a question mark in the path.
✗ Incorrect
In NestJS (and Express), adding a question mark after a parameter makes it optional. So ':category?' matches zero or one segment. Other options are invalid syntax or mean different things.
❓ state_output
expert3:00remaining
What is the output of this controller with nested route parameters?
Given this NestJS controller snippet:
What is the response body when a client requests
@Controller('users')
export class UserController {
@Get(':userId/posts/:postId')
getPost(@Param() params: { userId: string; postId: string }) {
return `User ${params.userId} Post ${params.postId}`;
}
}What is the response body when a client requests
/users/7/posts/15?Attempts:
2 left
💡 Hint
The @Param() decorator without argument returns an object with all parameters.
✗ Incorrect
The params object contains userId and postId extracted from the URL. So the returned string uses those values correctly.