Routes & Decorators — Series 2

Preview — 3 of 10 questions

What path does this handler respond to?

javascript
@Controller()
export class AppController {
  @Get('health')
  health() { return { status: 'ok' }; }
}
A/app/health, derived from the controller's class name
BNothing — a prefix is mandatory, so the route is never registered
C/health, because an empty @Controller() contributes no prefix
DBoth /health and /, since an empty prefix also registers a root route

How does Nest handle the returned promise?

javascript
@Get()
async findAll(): Promise<Cat[]> {
  return this.catsService.findAll();
}
AIt awaits the promise and serialises the resolved value as the response body; a rejection is routed to the exception layer
BIt serialises the promise object itself, producing {} in the response
CIt requires @Res() to be injected before a handler may be async
DIt converts the handler into a Server-Sent Events stream

What does the @Headers('x-api-key') decorator return?

javascript
@Get('profile')
getProfile(@Headers('x-api-key') apiKey: string) { /* ... */ }
AThe raw header block as a single string, exactly as it arrived on the wire
BAn array of every header whose name starts with x-
Cundefined unless the header name is registered in main.ts
DThe value of that one header, looked up case-insensitively; omitting the argument returns the whole headers object

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.