All quizzesHard
Controller Internals — Series 3
Preview — 3 of 10 questions
What do these three decorators store, and what consumes it?
javascript
@Get(':id')
findOne(@Param('id') id: string, @Query('full') full: string, @Headers('accept') accept: string) {}AThree separate metadata keys, one per decorator kind, each read by its own binder
BA wrapper function per parameter, invoked with the request at call time
COne route-arguments metadata entry per parameter, recording a numeric paramtype (param, query, headers, body, …), the optional key and any pipes — which a single factory then reads at call time, switching on the paramtype to pull the value out of the request
DThe parameter's name, which the factory matches against properties of the request object
What do these two reads return?
javascript
const path = this.reflector.get<string>(PATH_METADATA, CatsController);
const method = this.reflector.get<number>(METHOD_METADATA, CatsController.prototype.findOne);AThe controller's prefix ('cats') and the handler's HTTP method as the numeric RequestMethod enum value — the same metadata the router explorer reads when building the route table, which is why tooling can reconstruct the full route map from the class alone
BThe fully-resolved URL including the global prefix and version
Cundefined, because route metadata is consumed and removed during bootstrap
DThe compiled regular expression the router uses for matching
What status does the error path produce?
javascript
@Post('validate')
@HttpCode(200)
validate(@Body() dto: ValidateDto) {
if (!dto.token) throw new BadRequestException('token required');
return { ok: true };
}A200, because @HttpCode applies to every response from the handler
B500, since the declared status conflicts with the exception's
C204, as no body was produced
D400 — @HttpCode sets the status for a successful return, while an exception's status comes from the exception itself as the filter layer builds the response
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.