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

bookWorking 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.

question mark

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

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  7

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  7
some-alt