Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

HTML example

This is an example of how to return an HTML response.

You can also preview it at https://andreterron-htmlExample.web.val.run?name=Andre

1
2
3
4
5
6
7
8
9
10
11
12
// View at https://andreterron-htmlExample.web.val.run?name=Andre
export default async function(req: Request): Promise<Response> {
const query = new URL(req.url).searchParams;
// Read name from the querystring or body. Defaults to "you" if not present.
const name = query.get("name") || (await req.json().catch(() => ({}))).name || "you";
// Returns the HTML response
return new Response(`<h1>Hi ${name}!</h1>`, {
headers: { "Content-Type": "text/html" },
});
}
ocu-htmlexample.web.val.run
April 22, 2024