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/?q=fetch&page=128&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 8641 results for "fetch"(1451ms)

val_to_project_converterredirectService.ts12 matches

@charmaine•Updated 2 weeks ago
28 const projectUrl = `https://www.val.town/x/${username}/${projectName}`;
29
30 // First, get the project ID by fetching the project details
31 let projectId;
32 let endpointUrl: string | undefined; // Initialize as undefined, explicitly type
33 try {
34 const projectResponse = await fetch(`https://api.val.town/v1/alias/projects/${username}/${projectName}`, {
35 headers: {
36 "Authorization": `Bearer ${apiKey}`,
49 }
50
51 // Fetch the project files to get the endpoint URL
52 const filesResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files?path=`, {
53 headers: {
54 "Authorization": `Bearer ${apiKey}`,
57
58 if (!filesResponse.ok) {
59 // Still throw if fetching files fails
60 throw new Error(`Failed to get project files: ${filesResponse.status}`);
61 }
73 }
74 } catch (error) {
75 // Catch errors from fetching project details or files (but not the missing endpoint specifically)
76 console.error("Error getting project details or files:", error);
77 // Rethrow because fetching project details is critical for proceeding
78 throw new Error(`Error preparing project details: ${error.message}`);
79 }
97 try {
98 // First, get the val ID
99 const valResponse = await fetch(`https://api.val.town/v1/alias/${valOwner}/${valName}`, {
100 headers: {
101 "Authorization": `Bearer ${apiKey}`,
104
105 if (!valResponse.ok) {
106 throw new Error(`Failed to fetch val details: ${valResponse.status}`);
107 }
108
122 const redirectCode = `export default async function(req: Request): Promise<Response> {
123 const url = new URL(req.url);
124 return fetch(new URL(url.pathname + url.search, "${endpointUrl}"), {
125 method: req.method,
126 headers: req.headers,
148 console.log(`Version update body for ${valOwner}/${valName}:`, JSON.stringify(versionUpdateBody).substring(0, 200) + "...");
149
150 const versionUpdateResponse = await fetch(versionUpdateUrl, {
151 method: "POST",
152 headers: {
174 };
175
176 const readmeUpdateResponse = await fetch(readmeUpdateUrl, {
177 method: "PUT", // Use PUT as documented for updating val properties
178 headers: {

val_to_project_converterprojectService.ts12 matches

@charmaine•Updated 2 weeks ago
3// Define an intermediate type for the processing array
4interface ProcessingValInfo extends ValInfo {
5 val?: any; // Store the fetched val data here
6 success: boolean;
7 error?: string;
34 // Use existing project
35 projectId = existingProjectId;
36 // Fetch existing project details to get name and author
37 const projectDetailsResponse = await fetch(`https://api.val.town/v1/projects/${projectId}`, {
38 headers: { "Authorization": `Bearer ${apiKey}` },
39 });
40 if (!projectDetailsResponse.ok) {
41 const errorText = await projectDetailsResponse.text();
42 throw new Error(`Failed to fetch existing project details: ${errorText}`);
43 }
44 const projectDetails = await projectDetailsResponse.json();
67
68 // Create the new project
69 const projectResponse = await fetch("https://api.val.town/v1/projects", {
70 method: "POST",
71 headers: {
100 const convertedVals: ProcessingValInfo[] = []; // Use the defined type here
101
102 // First pass: fetch all vals and track them
103 for (const valInfo of vals) {
104 try {
105 // Fetch the val details
106 const valResponse = await fetch(`https://api.val.town/v1/alias/${valInfo.username}/${valInfo.valName}`, {
107 headers: { "Authorization": `Bearer ${apiKey}` },
108 });
115 valName: valInfo.valName,
116 success: false,
117 error: `Failed to fetch val: ${errorText}`,
118 });
119 continue;
131 username: valInfo.username,
132 valName: valInfo.valName,
133 val: val, // Store the fetched val
134 success: true,
135 });
155
156 // Add the file to the project (use the determined projectId)
157 const fileResponse = await fetch(`https://api.val.town/v1/projects/${projectId}/files?path=${filePath}`, {
158 method: "POST",
159 headers: {
188 // Generate and add README.md
189 const readmeContent = generateReadme(finalProjectName, vals, convertedVals);
190 await fetch(`https://api.val.town/v1/projects/${projectId}/files/README.md`, {
191 method: "POST",
192 headers: {

hiiiiii213123123123simpleAnalytics1 match

@charmaine•Updated 2 weeks ago
32 let func = `(async () => {
33 try {
34 await fetch(import.meta.url, {
35 method: "POST",
36 headers: {

cerebras_coderindex.ts1 match

@sameeksha•Updated 2 weeks ago
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({

cerebras_coderindex.ts1 match

@grosm4n•Updated 2 weeks ago
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({
28
29 // create http request
30 const res = await fetch("https://api.capacities.io/save-to-daily-note", {
31 method: "POST",
32 headers: {
28
29 // create http request
30 const res = await fetch("https://api.capacities.io/save-to-daily-note", {
31 method: "POST",
32 headers: {

stevensDemosendDailyBrief.ts1 match

@arawlins•Updated 2 weeks ago
135 const lastSunday = today.startOf("week").minus({ days: 1 });
136
137 // Fetch relevant memories using the utility function
138 const memories = await getRelevantMemories();
139

stevensDemoNotebookView.tsx12 matches

@arawlins•Updated 2 weeks ago
67 const [currentPage, setCurrentPage] = useState(1);
68
69 const fetchMemories = useCallback(async () => {
70 setLoading(true);
71 setError(null);
72 try {
73 const response = await fetch(API_BASE);
74 if (!response.ok) {
75 throw new Error(`HTTP error! status: ${response.status}`);
78 setMemories(data);
79 } catch (e) {
80 console.error("Failed to fetch memories:", e);
81 setError(e.message || "Failed to fetch memories.");
82 } finally {
83 setLoading(false);
86
87 useEffect(() => {
88 fetchMemories();
89 }, [fetchMemories]);
90
91 const handleAddMemory = async (e: React.FormEvent) => {
100
101 try {
102 const response = await fetch(API_BASE, {
103 method: "POST",
104 headers: { "Content-Type": "application/json" },
112 setNewMemoryTags("");
113 setShowAddForm(false);
114 await fetchMemories();
115 } catch (e) {
116 console.error("Failed to add memory:", e);
123
124 try {
125 const response = await fetch(`${API_BASE}/${id}`, {
126 method: "DELETE",
127 });
129 throw new Error(`HTTP error! status: ${response.status}`);
130 }
131 await fetchMemories();
132 } catch (e) {
133 console.error("Failed to delete memory:", e);
155
156 try {
157 const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
158 method: "PUT",
159 headers: { "Content-Type": "application/json" },
164 }
165 setEditingMemory(null);
166 await fetchMemories();
167 } catch (e) {
168 console.error("Failed to update memory:", e);

stevensDemoindex.ts2 matches

@arawlins•Updated 2 weeks ago
135 ));
136
137// HTTP vals expect an exported "fetch handler"
138export default app.fetch;

fetchPaginatedData2 file matches

@nbbaier•Updated 3 weeks ago

FetchBasic1 file match

@fredmoon•Updated 3 weeks ago