Skip to content

Response

Byte includes utility functions to create static response handlers:

import { send } from '@bit-js/byte';
// Send body
app.get('/body', send.body('Hi'));
// Send plain text
app.get('/text', send.text('Hi'));
// Send JSON
app.get('/info', send.json({ message: 'Hi' }));
// Send HTML
app.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.