Skip to content

RequestMappingMetadata

reference
2 min readUpdated

Kind: Interface

Source: packages/common/decorators/http/request-mapping.decorator.ts

Part of: Common

RequestMappingMetadata describes the routing information attached to an HTTP request handler. It combines one or more URL paths with a RequestMethod, allowing request-mapping decorators and routing infrastructure to register controller endpoints consistently.

Properties

PropertyType
path`string
methodRequestMethod

Diagram

mermaid
graph LR
  A[RequestMappingMetadata] --> B[path: string | string[]]
  A --> C[method: RequestMethod]
  B --> D[Single route path]
  B --> E[Multiple route paths]
  C --> F[HTTP verb]
  F --> G[Router registration]

Usage

ts
import { RequestMethod } from '@nestjs/common';
import type { RequestMappingMetadata } from './request-mapping.decorator';

const mapping: RequestMappingMetadata = {
  path: ['/users', '/accounts'],
  method: RequestMethod.GET,
};

// Example decorator metadata consumed by the HTTP router.
function registerRoute(metadata: RequestMappingMetadata) {
  for (const path of Array.isArray(metadata.path)
    ? metadata.path
    : [metadata.path]) {
    console.log(`Registering ${RequestMethod[metadata.method]} ${path}`);
  }
}

registerRoute(mapping);

AI Coding Instructions

  • Use path as a string for a single route or a string array when the same handler supports multiple routes.
  • Always provide a valid RequestMethod enum value; do not use raw HTTP method strings unless converted first.
  • Normalize path to an array before iterating over route mappings in router integration code.
  • Keep this metadata focused on route path and HTTP method; add unrelated handler metadata through separate interfaces or decorators.

How it works

Was this page helpful?

Download as PDF
RequestMappingMetadata — NestJS head-to-head