Bird
0
0

Which of the following is the correct syntax to apply ValidationPipe to a single route handler in NestJS?

easy📝 Syntax Q3 of 15
NestJS - Pipes
Which of the following is the correct syntax to apply ValidationPipe to a single route handler in NestJS?
A@UsePipes(new ValidationPipe())\n@Get()\ngetData() {}
B@UseGuards(new ValidationPipe())\n@Get()\ngetData() {}
C@UseFilters(new ValidationPipe())\n@Get()\ngetData() {}
D@UseInterceptors(new ValidationPipe())\n@Get()\ngetData() {}
Step-by-Step Solution
Solution:
  1. Step 1: Recall the decorator for pipes

    ValidationPipe is applied using the @UsePipes() decorator on route handlers or controllers.
  2. Step 2: Eliminate other decorators

    @UseGuards is for auth, @UseFilters for exceptions, @UseInterceptors for interceptors, so they are incorrect here.
  3. Final Answer:

    @UsePipes(new ValidationPipe())\n@Get()\ngetData() {} -> Option A
  4. Quick Check:

    ValidationPipe on route = @UsePipes [OK]
Quick Trick: Use @UsePipes to apply ValidationPipe on routes [OK]
Common Mistakes:
  • Using @UseGuards instead of @UsePipes
  • Applying ValidationPipe with filters or interceptors
  • Missing parentheses after ValidationPipe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes