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

bookHandling Query Parameters

メニューを表示するにはスワイプしてください

Query parameters allow you to pass additional data in the URL. They are commonly used for filtering, sorting, or searching.

A query parameter is added after the ? symbol:

/users?role=admin

To access query parameters in Nest.js, use the @Query() decorator:

import { Controller, Get, Query } from '@nestjs/common';

@Controller('users')
export class UsersController {
  @Get()
  getUsers(@Query('role') role: string) {
    return `Role: ${role}`;
  }
}

  • @Query('role'): extracts the value from the URL;
  • role: contains the query parameter value.

You can also access multiple query parameters:

/users?role=admin&active=true

@Get()
getUsers(
  @Query('role') role: string,
  @Query('active') active: string
) {
  return { role, active };
}

Query parameters are optional and are often used to control how data is returned.

question mark

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

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

すべて明確でしたか?

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

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

セクション 1.  8

AIに質問する

expand

AIに質問する

ChatGPT

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

セクション 1.  8
some-alt