Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/image-url.jpg%20%22Image%20title%22?q=fetch&page=1084&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=fetch

Returns an array of strings in format "username" or "username/projectName"

Found 13561 results for "fetch"(1450ms)

dbpediamain.tsx8 matches

@ejfox•Updated 9 months ago
24 if (urlQuery) {
25 setQuery(urlQuery);
26 fetchResults(urlQuery);
27 }
28 }, []);
29
30 const fetchResults = async (searchQuery) => {
31 const response = await fetch(`/api/search?query=${encodeURIComponent(searchQuery)}`);
32 const data = await response.json();
33 setResults(data);
38 if (query) {
39 window.history.pushState({}, "", `?query=${encodeURIComponent(query)}`);
40 fetchResults(query);
41 }
42 };
125if (typeof document !== "undefined") { client(); }
126
127async function fetchDBpediaResults(query: string) {
128 const lookupResponse = await fetch(
129 `https://lookup.dbpedia.org/api/search?query=${encodeURIComponent(query)}&format=json&maxResults=5`,
130 );
143 `;
144
145 const sparqlResponse = await fetch(
146 `https://dbpedia.org/sparql?query=${encodeURIComponent(sparqlQuery)}&format=json`,
147 );
171 }
172
173 const results = await fetchDBpediaResults(query);
174
175 return new Response(JSON.stringify(results), {

dotShortcutmain.tsx2 matches

@pomdtr•Updated 9 months ago
12 const [author, name] = subdomain.split("-");
13
14 const resp = await fetch(`https://api.val.town/v1/alias/${author}/${name}`);
15 if (!resp.ok) {
16 console.error("failed to fetch val infos");
17 return;
18 }

scrape2mdmain.tsx7 matches

@taras•Updated 9 months ago
57 }
58
59 const fetch_response = await fetch(url.toString(), {
60 method: req.method,
61 headers: new Headers({
64 "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8",
65 "Accept-Language": "en-US,en;q=0.5",
66 "Sec-Fetch-Site": "cross-site",
67 "Sec-Fetch-Mode": "navigate",
68 "Sec-Fetch-User": "?1",
69 "Sec-Fetch-Dest": "document",
70 "Referer": "https://www.google.com/",
71 "sec-ch-ua": `"Not A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"`,
76 }),
77 });
78 const contentType = fetch_response.headers.get("content-type");
79 const response_text = await fetch_response.text();
80 // We only handle html, pass content through otherwise
81 if (!contentType?.includes("text/html")) {

OpenAImain.tsx1 match

@hash0000ff•Updated 9 months ago
12 * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
13 * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
14 * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
15 * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
16 * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.

redditImageGrabmain.tsx7 matches

@yawnxyz•Updated 9 months ago
2import React, { useEffect, useState } from "https://esm.sh/react";
3import { createRoot } from "https://esm.sh/react-dom/client";
4import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
5
6const subreddits = ["IdiotsInCars"];
7
8const fetchWithImage = async (subreddit: string) => {
9 const { data: { children } } = await fetchJSON(
10 `https://www.reddit.com/r/${subreddit}.json`,
11 );
24};
25
26const fetchAllReddits = async () => {
27 const posts = (await Promise.all(subreddits.map(fetchWithImage))).flat();
28 return posts;
29};
45
46 useEffect(() => {
47 fetch("/api/posts").then(ok => ok.json())
48 .then(posts => setPosts(posts));
49 }, []);
64export default async function server(req: Request): Promise<Response> {
65 if (req.url.endsWith("/api/posts")) {
66 const posts = await fetchAllReddits();
67 posts.sort((a, b) => b.score - a.score);
68 return Response.json(posts);

lucia_honomain.tsx1 match

@saolsen•Updated 9 months ago
548 req: Request,
549): Promise<Response> {
550 return await app.fetch(req);
551}

pr0nmain.tsx7 matches

@roramigator•Updated 9 months ago
2import React, { useEffect, useState } from "https://esm.sh/react";
3import { createRoot } from "https://esm.sh/react-dom/client";
4import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
5
6const subreddits = ["Battletops", "AverageBattlestations", "desksetup"];
7
8const fetchWithImage = async (subreddit: string) => {
9 const { data: { children } } = await fetchJSON(
10 `https://www.reddit.com/r/${subreddit}.json`,
11 );
24};
25
26const fetchAllReddits = async () => {
27 const posts = (await Promise.all(subreddits.map(fetchWithImage))).flat();
28 return posts;
29};
45
46 useEffect(() => {
47 fetch("/api/posts").then(ok => ok.json())
48 .then(posts => setPosts(posts));
49 }, []);
64export default async function server(req: Request): Promise<Response> {
65 if (req.url.endsWith("/api/posts")) {
66 const posts = await fetchAllReddits();
67 posts.sort((a, b) => b.score - a.score);
68 return Response.json(posts);

OpenAImain.tsx1 match

@arthrod•Updated 9 months ago
12 * @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
13 * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
14 * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
15 * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
16 * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.

valWallmain.tsx9 matches

@iamseeley•Updated 9 months ago
36
37async function generateGraph(username) {
38 console.log(`Fetching contributions for ${username}`);
39 try {
40 const contributionData = await fetchContributions(username);
41 const totalContributions = Object.values(contributionData).reduce((sum, count) => sum + count, 0);
42 console.log(`Total contributions: ${totalContributions}`);
56}
57
58async function fetchContributions(username) {
59 const contributionMap = {};
60 const valsUrl = `https://api.val.town/v1/alias/${username}/vals`;
61 const valsResponse = await fetch(valsUrl);
62 if (!valsResponse.ok) {
63 throw new Error(`HTTP error! status: ${valsResponse.status}`);
83 contributionMap[creationDate] = (contributionMap[creationDate] || 0) + 1;
84
85 await fetchValVersions(val.id, contributionMap, creationDate);
86 }
87 }
90}
91
92async function fetchValVersions(valId, contributionMap, creationDate) {
93 const versionsUrl = `https://api.val.town/v1/vals/${valId}/versions`;
94 try {
95 const versionsResponse = await fetch(versionsUrl);
96 if (!versionsResponse.ok) {
97 throw new Error(`HTTP ${versionsResponse.status}`);
115 }
116 } catch (error) {
117 console.error(`Failed to fetch versions for val ${valId}:`, error.message);
118 }
119}
199}
200
201export default app.fetch;

spacexapimain.tsx1 match

@moe•Updated 9 months ago
30
31async function loadPage(url) {
32 const response = await fetch(url)
33 const body = await response.text()
34 const $ = cheerio.load(body)

GithubPRFetcher

@andybak•Updated 2 days ago

proxiedfetch1 file match

@jayden•Updated 3 days ago