Built and signed on GitHub ActionsBuilt and signed on GitHub Actions
Simple functions for creating and manipulating HTTP Responses.
Response functions
A bunch of functions to aid creation and manipulation of the standard Response.
Response creation shortcuts
These functions are simple common shortcuts for creating Response objects.
Error responses return plain text messages, if you want an alternative
content-type, use a new Response
instead, or use some middleware or an
interceptor to modify the response, wrapping
the message in a richer format.
If a particular status hasn't been covered it may be because:
- possible options are too complex to cover in a simple function, best to just
use
new Response
in that case - it's been deprecated, or superseded by a preferred alternative (eg. 301 => 308, 302 => 307)
- it's not yet been required in a real situation
Please raise an issue to request additional functions if you have a genuine need for it, and can suggest a simple and generally reusable signature.
Common Content-Type Responses
- html() creates a
200 OK
response with atext/html
content-type. - json() serializes the given value to JSON in a
200 OK
response with anapplication/json
content-type.
Header manipulation
The functions appendHeaders() and setHeaders() allow you to alter the headers of a Response, including copying the Response if it's immutable.
These can be useful within middleware/interceptors to add additional headers to the Response from a handler.
Body manipulation
- replaceBody() allows you to duplicate a Response but with an alternative body.
- prependDocType() allows you to prepend
<!DOCTYPE html>
to a html body whilst preserving its streaming capabilities, mostly useful in conjunction with JSX generated content.
Conditional Responses
- conditional() will inspect a given Request and Response,
and determine whether you need to actually return the Response or a
304 Not Modified
instead.