nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.09k stars 541 forks source link

Suggestion: Return "204 No Content" by default in DELETE actions #691

Open Char2sGu opened 3 years ago

Char2sGu commented 3 years ago

According to the REST specification, a 204 should be returned if a DELETE action is successfully performed, but now the lib returns a 200 instead.

SDToews commented 2 years ago

is there a way to change the response code though options or something?

minlare commented 1 year ago

I'm handling this way:

import { Delete, HttpCode, HttpStatus } from '@nestjs/common';

@Delete(':id')
@HttpCode(HttpStatus.NO_CONTENT)
...

Would be nice if @Delete default was 204 with the option to override

sovla commented 2 months ago

Hi everyone,

Just passing by, but I was thinking that this issue could be nicely handled with a custom decorator. For example:

import { Delete, HttpCode, HttpStatus, applyDecorators } from '@nestjs/common';

export const DeleteWithNoContent = (path?: string | string[]) =>
  applyDecorators(Delete(path), HttpCode(HttpStatus.NO_CONTENT));

This way, you can consistently return 204 No Content for DELETE actions without needing to manually specify the status code each time.