ParseUUIDPipe

Validates that a parameter is a well-formed UUID of the given version.

Since NestJS 10/11 Spec ↗

Syntax

new ParseUUIDPipe(options?: { version })

Parameters

NameTypeRequiredDescription
options object No Optional version ("3" | "4" | "5") and errorHttpStatusCode.

Returns

string — The validated UUID string passed to the handler.

Throws

  • BadRequestException — Thrown when the value is not a valid UUID.

Examples

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

@Controller('users')
export class UsersController {
  @Get(':id')
  findOne(
    @Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
  ) {
    return { id };
  }
}

Notes

Defaults to accepting any UUID version. Specify `version` to enforce a particular format, useful when IDs are generated as v4 UUIDs.