204 No Content
Success, but there is absolutely nothing to send back in the response body. Common for successful DELETE operations.
When and Why to Use It
Section titled “When and Why to Use It”Use this when a request succeeded, but there is literally no data to send back. The most common use case is a successful DELETE request. ‘I deleted it, mission accomplished, nothing else to say.‘
Usage Examples
Section titled “Usage Examples”import { HttpCode, get } from 'shokupan';
export const getResource = get('/resource', () => { return { message: 'No Content' };}).pipe(HttpCode(204));import { Controller, Get, HttpCode } from 'shokupan';
@Controller('/api')export class ExampleController { @Get('/resource') @HttpCode(204) getResource() { return { message: 'No Content' }; }}import express from 'express';const app = express();
app.get('/resource', (req, res) => { res.status(204).json({ message: 'No Content' });});import { Controller, Get, HttpCode } from '@nestjs/common';
@Controller('api')export class ExampleController { @Get('resource') @HttpCode(204) getResource() { return { message: 'No Content' }; }}import Koa from 'koa';const app = new Koa();
app.use(async ctx => { if (ctx.path === '/resource' && ctx.method === 'GET') { ctx.status = 204; ctx.body = { message: 'No Content' }; }});