All quizzesMedium
Advanced Routing — Series 3
Preview — 3 of 10 questions
Which handler serves GET /cats/featured?
javascript
@Module({ imports: [AdminModule, CatsModule] })
export class AppModule {}
// AdminModule → @Controller('cats') with @Get(':id')
// CatsModule → @Controller('cats') with @Get('featured')Afeatured, because a literal segment always outranks a parameter
BNeither; the ambiguity is reported at startup
CBoth, with the results merged
DAdminModule's :id handler — routes are registered in module-scanning order, and matching is first-match-wins, so a parameterised route registered by an earlier module shadows a literal route in a later one
A client sends HEAD /cats/42. What happens?
javascript
@Get(':id')
findOne(@Param('id') id: string) { return this.catsService.findOne(id); }AThe GET handler runs and its headers are returned with the body stripped, because the platform router answers HEAD from the matching GET route
BA 404, since no @Head() handler is declared
CA 405 Method Not Allowed
DThe handler runs and the full body is sent, contrary to the HTTP specification
The handler returns a plain object. What does Nest do?
javascript
Accept: application/xmlAIt returns 406 Not Acceptable, since only JSON is supported
BIt converts the object to XML using a built-in serialiser
CIt ignores the header and serialises to JSON: Nest's default response pipeline has one representation, so honouring Accept means implementing it yourself — typically an interceptor that inspects the header and formats accordingly
DIt selects a format based on the request's Content-Type instead
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.