Bird
0
0

Which of the following is the correct way to extract a route parameter named id in a NestJS controller method?

easy📝 Syntax Q12 of 15
NestJS - Database with TypeORM
Which of the following is the correct way to extract a route parameter named id in a NestJS controller method?
Aasync getItem(@Body('id') id: string) {}
Basync getItem(@Query('id') id: string) {}
Casync getItem(@Param('id') id: string) {}
Dasync getItem(@Headers('id') id: string) {}
Step-by-Step Solution
Solution:
  1. Step 1: Identify the decorator for route parameters

    @Param is used to extract parameters from the URL path, such as /items/:id.
  2. Step 2: Check other decorators and their uses

    @Body extracts data from the request body, @Query from query strings, and @Headers from HTTP headers, so they don't get route params.
  3. Final Answer:

    async getItem(@Param('id') id: string) {} -> Option C
  4. Quick Check:

    Route param = @Param [OK]
Quick Trick: Use @Param to get URL parameters in NestJS [OK]
Common Mistakes:
  • Using @Body to get URL params
  • Using @Query for route params
  • Confusing @Headers with @Param

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes