Bird
0
0

You want to transform a nested response object to only include specific fields globally. Which approach is best in NestJS?

hard📝 Conceptual Q8 of 15
NestJS - Interceptors
You want to transform a nested response object to only include specific fields globally. Which approach is best in NestJS?
AUse a pipe to filter response fields
BModify the controller to return filtered data
CCreate a global interceptor that maps and returns only needed fields
DUse a guard to restrict response fields
Step-by-Step Solution
Solution:
  1. Step 1: Identify global transformation needs

    Global response changes are best done with interceptors.
  2. Step 2: Understand roles of other features

    Pipes transform inputs, guards handle authorization, controllers can do it but not globally.
  3. Final Answer:

    Create a global interceptor that maps and returns only needed fields -> Option C
  4. Quick Check:

    Global response filtering = Global interceptor [OK]
Quick Trick: Use interceptors for global response shaping [OK]
Common Mistakes:
  • Using pipes for response output filtering
  • Changing controllers for global effect
  • Misusing guards for data filtering

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes