Basic examples
HTTP vals, unlike other vals, expose a public endpoint.
An HTTP val that works with the Web API takes a Request object as input and returns a Response object.
The most basic example can ignore the request and just return a response, even using a shorthand method like Response.json, which is part of the web standard.
A slightly more built-out val can return HTML along with the correct Content-Type header:
Now let’s work with the request: this echoes request headers back in the response:
We can grab query parameters using the web standard URLSearchParams class:
You can also get the body of POST requests using the Request object, for example if you had an endpoint that received JSON:
To obtain the HTTP endpoint for your HTTP val, use the “Copy HTTP endpoint” feature (located in the val’s sidebar, or in its … menu).