201 Created
Success! The request worked and resulted in a brand new resource being created (e.g., a new user account).
When and Why to Use It
Section titled “When and Why to Use It”Use this specifically when a POST or PUT request actually creates a brand new record in your database. It’s best practice to also include a ‘Location’ header pointing to the new resource’s URL.
Usage Examples
Section titled “Usage Examples”import { HttpCode, get } from 'shokupan';
export const getResource = get('/resource', () => { return { message: 'Created' };}).pipe(HttpCode(201));import { Controller, Get, HttpCode } from 'shokupan';
@Controller('/api')export class ExampleController { @Get('/resource') @HttpCode(201) getResource() { return { message: 'Created' }; }}import express from 'express';const app = express();
app.get('/resource', (req, res) => { res.status(201).json({ message: 'Created' });});import { Controller, Get, HttpCode } from '@nestjs/common';
@Controller('api')export class ExampleController { @Get('resource') @HttpCode(201) getResource() { return { message: 'Created' }; }}import Koa from 'koa';const app = new Koa();
app.use(async ctx => { if (ctx.path === '/resource' && ctx.method === 'GET') { ctx.status = 201; ctx.body = { message: 'Created' }; }});