Skip to content

Basic examples

A val that works with the Web API takes a Request object as input and needs to return 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: