All quizzesMedium
Advanced Routing — Series 2
Preview — 3 of 10 questions
What is the resulting URL layout?
javascript
app.setGlobalPrefix('api', {
exclude: [{ path: 'health', method: RequestMethod.GET }],
});AEvery route is served twice, once with and once without the prefix
BEvery controller route is served under /api/..., except GET /health, which stays at the root — the usual reason being that load balancers and uptime probes expect a fixed, unversioned path
COnly controllers that declare @Controller({ prefix: true }) receive the prefix
DThe prefix applies to POST routes only; GET routes are left untouched
What does this register?
javascript
@Controller(['cats', 'kittens'])
export class CatsController {
@Get(':id')
findOne(@Param('id') id: string) { /* ... */ }
}ANothing — @Controller() accepts a single string only, so the array is ignored
BOnly /cats/:id; the remaining entries are treated as documentation
C/cats/:id plus a permanent redirect from /kittens/:id
DTwo independent routes, /cats/:id and /kittens/:id, both handled by the same method
For a body of { "name": "Bombay", "age": 3 }, what is injected?
javascript
@Post()
create(@Body('name') name: string, @Body() dto: CreateCatDto) {}Aname is 'Bombay' and dto is the whole parsed body object
Bname is undefined, because @Body() accepts no arguments
CBoth receive the whole body; the argument is only a label
Dname is 'Bombay' and dto is { age: 3 }, with the extracted key removed
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.