NestJS - InterceptorsYou 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 fieldsBModify the controller to return filtered dataCCreate a global interceptor that maps and returns only needed fieldsDUse a guard to restrict response fieldsCheck Answer
Step-by-Step SolutionSolution:Step 1: Identify global transformation needsGlobal response changes are best done with interceptors.Step 2: Understand roles of other featuresPipes transform inputs, guards handle authorization, controllers can do it but not globally.Final Answer:Create a global interceptor that maps and returns only needed fields -> Option CQuick Check:Global response filtering = Global interceptor [OK]Quick Trick: Use interceptors for global response shaping [OK]Common Mistakes:Using pipes for response output filteringChanging controllers for global effectMisusing guards for data filtering
Master "Interceptors" in NestJS9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallPerf
More NestJS Quizzes Database with Prisma - Prisma migrations - Quiz 12easy Database with TypeORM - Repository pattern - Quiz 12easy Guards - Why guards control access - Quiz 13medium Guards - Guard binding levels - Quiz 12easy Interceptors - Logging interceptor - Quiz 11easy Interceptors - Why interceptors add cross-cutting logic - Quiz 8hard Middleware - Why middleware processes requests before handlers - Quiz 9hard Middleware - Why middleware processes requests before handlers - Quiz 4medium Pipes - Custom pipes - Quiz 12easy Pipes - Built-in pipes (ParseIntPipe, ParseBoolPipe) - Quiz 13medium