Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Working with Route Parameters | Controllers and Routing
Building Backend Applications with Nest.js

bookWorking with Route Parameters

Desliza para mostrar el menú

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.

question mark

What decorator is used to access route parameters in Nest.js?

Selecciona la respuesta correcta

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 2. Capítulo 4

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

Sección 2. Capítulo 4
some-alt