http_request_examplemain.tsx11 matches
4*/
56// To make a request to a server, you use the `fetch` API.
7let resp = await fetch("https://example.com");
89// The response is a `Response` object. This contains the status code, headers,
15// The response body can also be read as JSON, an ArrayBuffer, or a Blob. A body
16// can be read only once.
17resp = await fetch("https://example.com");
18await resp.arrayBuffer();
19/** or await resp.json(); */
2122// The response body can also be streamed in chunks.
23resp = await fetch("https://example.com");
24for await (const chunk of resp.body!) {
25console.log("chunk", chunk);
28// When making a request, you can also specify the method, headers, and a body.
29const body = `{"name": "Deno"}`;
30resp = await fetch("https://example.com", {
31method: "POST",
32headers: {
37});
3839// `fetch` also accepts a `Request` object instead of URL + options.
40const req = new Request("https://example.com", {
41method: "DELETE",
42});
43resp = await fetch(req);
4445// Instead of a string, the body can also be any typed array, blob, or
59});
6061// Forms can also be sent with `fetch` by using a `FormData` object as the body.
62const formData = new FormData();
63formData.append("name", "Deno");
64formData.append("file", new Blob(["Hello, World!"]), "hello.txt");
65resp = await fetch("https://example.com", {
66method: "POST",
67body: formData,
68});
6970// Fetch also supports streaming the request body.
71const bodyStream = new ReadableStream({
72start(controller) {
75},
76});
77resp = await fetch("https://example.com", {
78method: "POST",
79body: bodyStream,
fetsServerExamplemain.tsx1 match
21});
2223export default router.fetch;
1import { API_URL } from "https://esm.town/v/std/API_URL";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3import process from "node:process";
45export async function set(key: string, value: any) {
6let resp = await fetch(
7`${API_URL}/v1/vals`,
8{
82async function list(prefix?: string): Promise<{ key: string; size: number; lastModified: string }[]> {
83let querystring = prefix ? `?prefix=${encodeURIComponent(prefix)}` : "";
84const res = await fetch(`${API_URL}/v1/blob${querystring}`, {
85headers: {
86Authorization: `Bearer ${Deno.env.get("valtown")}`,
9596async function delete_(key: string) {
97const res = await fetch(`${API_URL}/v1/blob/${encodeURIComponent(key)}`, {
98method: "DELETE",
99headers: {
108109async function get(key: string) {
110const res = await fetch(`${API_URL}/v1/blob/${encodeURIComponent(key)}`, {
111headers: {
112Authorization: `Bearer ${Deno.env.get("valtown")}`,
127value = value.body;
128}
129const res = await fetch(`${API_URL}/v1/blob/${encodeURIComponent(key)}`, {
130method: "POST",
131headers: {
TODO_tootLatestPostsmain.tsx4 matches
9"https://jaandrle.github.io/feeds/nondev.xml",
10"https://jaandrle.github.io/feeds/dev.xml",
11].map(fetchRSS)))
12.flatMap(rss =>
13rss.entry
23}
2425import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
26import { parseXML } from "https://esm.town/v/stevekrouse/parseXML";
27function fetchRSS(url) {
28return fetchText(url)
29.then(parseXML)
30.then(xml => {
3const url = "https://example.com";
4const key = "exampleBlob";
5await blob.set(key, (await fetch(url)).body);
6console.log(await (await blob.get(key)).text());
1# Set Blob Storage via fetch Response body
23Inspired by [Wes Bos's tweet](https://twitter.com/wesbos/status/1775558324454392064?t=Pnx8jDyfF7wVbZJp0QnNJw&s=19) about Bun's elegant Filesystem API.
fireworks_ai_proxymain.tsx1 match
90// console.log(init);
91// console.log(init.body);
92const response = await fetch(url.toString(), init);
93const responseHeaders = new Headers(response.headers);
94// Special handling for /api/v1/models
cors_proxymain.tsx2 matches
52};
5354// Perform the fetch request to the destination URL
55const response = await fetch(destUrlString, init);
5657// Return the response from the destination URL, including CORS headers
getHashForUrlmain.tsx3 matches
3// Retrieves the URL, and returns a hash of its contents.
4export async function getHashForUrl(url: string): Promise<string> {
5// Fetch the content from the URL
6const response = await fetch(url);
7if (!response.ok) {
8throw new Error(`Failed to fetch URL: ${url}`);
9}
10const data = await response.arrayBuffer();