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.
https://www.val.town/embed/tmcw.jsonOkExample
A slightly more built-out val can return HTML along with the correct Content-Type header:
https://www.val.town/embed/tmcw.htmlExample
Now let’s work with the request: this echoes request headers back in the response:
https://www.val.town/embed/tmcw.headersExample
We can grab query parameters using the web standard URLSearchParams class: