Quick response
Sending response that will never change
import { Router, macro } from '@stricjs/router';
import { response } from '@stricjs/utils';
// Cache the payload and the response options
const badReq = response('Bad request', { status: 400 });
// The response payload can be anything that is serializable to a string
// That means you can put a number, string, boolean, null, undefined, arrays
// and objects as response payload (it will convert the payload to string)
// It does not work with Buffer, ArrayBuffer, typed arrays and streams
export default new Router()
.get('/', macro(() => new Response('Hi')))
// For other methods return a bad request
.all('/', badReq);
Last updated