Response
Byte includes utility functions to create static response handlers:
import { send } from '@bit-js/byte';
// Send bodyapp.get('/body', send.body('Hi'));
// Send plain textapp.get('/text', send.text('Hi'));
// Send JSONapp.get('/info', send.json({ message: 'Hi' }));
// Send HTMLapp.get('/page', send.html('<p>Hi</p>'));
All methods accept a response body and a ResponseInit
object as arguments.
For body
, text
and html
method, the response body can be in any format listed here,
while the json
method only accepts values that are serializable using JSON.stringify
.
Note that the responses create by these handlers do not contain status
, statusText
and headers
from the request context.