v5
April 3, 2024
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { API_URL } from "https://esm.town/v/std/API_URL";
import { rawFetch } from "https://esm.town/v/std/rawFetch";
/**
* Wraps the JavaScript Fetch function to anonymize where the request is
* coming from ([Docs β](https://docs.val.town/std/fetch))
*
* @param {string | URL} input - The URL to fetch
* @param {RequestInit} [requestInit] - Optional configuration data (HTTP
* method, headers, etc) ([Docs β](https://deno.land/api@v1.42.1?s=RequestInit))
*/
export async function fetch(input: string | URL, requestInit?: RequestInit) {
let query = new URLSearchParams({
url: input.toString(),
});
return rawFetch(`${API_URL}/v1/fetch?${query}`, {
...requestInit,
headers: {
"X-Valtown-Authorization": `Bearer ${Deno.env.get("valtown")}`,
...requestInit?.headers ?? {},
},
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
v5 was merged from the PR "Update JSDocs" by andreterron
Comments
Nobody has commented on this val yet: be the first!
v5
April 3, 2024