1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=43";
import { json_viewer } from "https://esm.town/v/stevekrouse/json_viewer";
export const weatherDescription = async (req: Request): Promise<Response> => {
let { pathname, searchParams } = new URL(req.url);
let apiURL = new URL("https://wttr.in");
apiURL.pathname = pathname;
apiURL.search = searchParams.toString();
apiURL.searchParams.set("format", "j1");
let data = await fetchJSON(apiURL.href, {
headers: {
"accept-language": req.headers.get("accept-language"),
},
});
return json_viewer(data)(req);
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.