Working with Route Parameters
Sveip for å vise menyen
Route parameters allow you to pass dynamic values in the URL.
For example, instead of requesting all users, you can request a specific user by ID.
Define a route parameter like this:
import { Controller, Get, Param } from '@nestjs/common';
@Controller('users')
export class UsersController {
@Get(':id')
getUserById(@Param('id') id: string) {
return `User ID: ${id}`;
}
}
:id: defines a dynamic part of the URL;@Param('id'): extracts the value from the URL;id: is passed into the method.
When you open:
/users/5
The response will be:
User ID: 5
You can use route parameters whenever you need to work with specific data, such as users, products, or orders.
Takk for tilbakemeldingene dine!
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Working with Route Parameters
Route parameters allow you to pass dynamic values in the URL.
For example, instead of requesting all users, you can request a specific user by ID.
Define a route parameter like this:
import { Controller, Get, Param } from '@nestjs/common';
@Controller('users')
export class UsersController {
@Get(':id')
getUserById(@Param('id') id: string) {
return `User ID: ${id}`;
}
}
:id: defines a dynamic part of the URL;@Param('id'): extracts the value from the URL;id: is passed into the method.
When you open:
/users/5
The response will be:
User ID: 5
You can use route parameters whenever you need to work with specific data, such as users, products, or orders.
Takk for tilbakemeldingene dine!