1import { fetch } from "https://esm.town/v/std/fetch";
2export default async function(request: Request) {
3 const url = new URL(request.url);
4 const h = url.searchParams.get("tdestination");
5 if (h) {
6 const resp = await fetch(decodeURIComponent(url.searchParams.get("tdestination")), {
7 method: request.method,
8 body: request.body,
13 }
14 else {
15 const resp = await fetch(decodeURIComponent(url.searchParams.get("destination")), {
16 method: request.method,
17 body: request.body,
3Get a Spotify Track Url using the Spotify Web API given an artist and a song title.
4
5Track info is cached by the query and also the spotify track id, so your popular queries won't have to fetch from Spotify over and over.
6
7## Examples
25`SPOTIFY_CLIENT_SECRET`
26
27Your access token is cached by `getSpotifyAccessToken` to avoid fetching over and over.
28
29
1import { blob } from "https://esm.town/v/std/blob?v=12";
2export default async function(interval: Interval) {
3 await fetch("https://tempguy-scarletsole.web.val.run/refresh");
4 const date = new Date();
5 await blob.setJSON("turnstileCron", { ptime: date.getTime(), ntime: interval.delay + interval.lastRunAt.getTime() });
117});
118
119export default app.fetch;
11 const API_KEY = process.env.GEMINI_API_KEY;
12
13 const response = await fetch(`https://generativelanguage.googleapis.com/v1beta/models?key=${API_KEY}`);
14
15 const data = await response.json();
22 return models;
23 } catch (error) {
24 console.error("Error fetching Gemini models:", error);
25 return [];
26 }
1# Fetch
2
3Learn how to use proxied fetch
1import { fetch } from "https://esm.town/v/std/fetch";
2
3let result = await fetch("https://api64.ipify.org?format=json");
4let json = await result.json();
5console.log(json.ip);
1export default async function getValsContextWindow(model: any) {
2 const readmeVals: any = await (await fetch("https://janpaul123-readmevals.web.val.run/")).json();
3
4 const API_URL = "https://api.val.town";
58 );
59 });
60 export default app.fetch;`,
61 },
62 {
118 {
119 prompt: "Write a val that accesses environment variables",
120 code: `const res = await fetch("${API_URL}/v1/me", {
121 headers: {
122 Authorization: \`Bearer \${Deno.env.get("valtown")}\`,
130 code: `import process from "node:process";
131
132 const res = await fetch("${API_URL}/v1/me", {
133 headers: {
134 Authorization: \`Bearer \${process.env.valtown}\`,
154 code: `import cheerio from "npm:cheerio";
155
156 const response = await fetch("https://example.com");
157 const body = await response.text();
158 const $ = cheerio.load(body);
528 {
529 role: "user",
530 content: "Write a val that fetches the weather in Brooklyn, NY",
531 },
532 {
533 role: "assistant",
534 content:
535 "```ts\nexport default async function(req: Request): Promise<Response> {\n const apiKey = Deno.env.get(\"METEO_KEY\");\n const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=40.6782&longitude=-73.9442&hourly=temperature_2m¤t_weather=true&apikey=${apiKey}`;\n\n const response = await fetch(apiUrl);\n const weatherData = await response.json();\n\n return new Response(JSON.stringify(weatherData), { headers: { \"Content-Type\": \"application/json\" } });\n}\n```",
536 },
537 {
542 role: "assistant",
543 content:
544 "```ts\n/** @jsxImportSource npm:hono@3/jsx */\nimport { Hono } from \"npm:hono\";\n\nconst app = new Hono();\napp.get(\"/\", async (c) => {\n return c.html(\n <div>\n <form>\n Your name: <input type=\"text\" name=\"name\" /> <input type=\"submit\" />\n </form>\n Hello {c.req.query(\"name\")}\n </div>,\n );\n});\nexport default app.fetch;\n```",
545 },
546 ...templatePrompts,
18
19export async function checkIp() {
20 const result = await fetch(`https://ipqualityscore.com/api/json/ip/${ipqsApiKey}/${ipAddress}`);
21 const newData = await result.json();
22
34 // YOU MAY NOW RUN THE FILE.
35
36 const data = await fetch(
37 `https://api.stage.teamsurfboard.com/api/v1/schedule?start=${start.toISOString()}&end=${end.toISOString()}`,
38 {
54
55function Demo({ data }) {
56 if (!data) return <p>Failed to fetch</p>;
57
58 function processData(data) {