Skip to content

Function: HttpCode()

ts
function HttpCode(statusCode): MethodDecorator;

Defined in: packages/core/src/decorators/http-code.decorator.ts:25

Decorator that sets the HTTP status code for the response.

Parameters

ParameterTypeDescription
statusCodenumberThe HTTP status code to return.

Returns

MethodDecorator

Example

typescript
@Post()
@HttpCode(201)
create() {
  return 'Created successfully';
}

@Get('not-found')
@HttpCode(404)
notFound() {
  return 'Resource not found';
}

Released under the MIT License.