428 Precondition Required
The server requires conditional headers to prevent ‘lost updates’ where two people edit a file at the same time.
When and Why to Use It
Section titled “When and Why to Use It”Use this to enforce safe collaborative editing. If a client tries to PUT updates to a shared document without specifying which exact version they are modifying, throw a 428 to force them to use safe conditional headers.
Usage Examples
Section titled “Usage Examples”import { HttpException, get } from 'shokupan';
export const getResource = get('/resource', () => { throw new HttpException('Precondition Required', 428);});import { Controller, Get, HttpException } from 'shokupan';
@Controller('/api')export class ExampleController { @Get('/resource') getResource() { throw new HttpException('Precondition Required', 428); }}import express from 'express';const app = express();
app.get('/resource', (req, res) => { res.status(428).json({ error: 'Precondition Required' });});import { Controller, Get, HttpException } from '@nestjs/common';
@Controller('api')export class ExampleController { @Get('resource') getResource() { throw new HttpException('Precondition Required', 428); }}import Koa from 'koa';const app = new Koa();
app.use(async ctx => { if (ctx.path === '/resource' && ctx.method === 'GET') { ctx.status = 428; ctx.body = { error: 'Precondition Required' }; }});