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?q=api&page=18&format=json

For typeahead suggestions, use the /typeahead endpoint:

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

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

Found 11661 results for "api"(3016ms)

34};
35
36// Types for Slack API
37type SlackMessage = {
38 blocks: any[];
323
324 // Get PR details
325 const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}`;
326 console.log("๐Ÿ” Fetching from GitHub API URL:", url);
327
328 let response;
335 },
336 });
337 console.log("๐Ÿ” GitHub API response received");
338 console.log("๐Ÿ” Response status:", response.status);
339 console.log("๐Ÿ” Response status text:", response.statusText);
346
347 if (!response.ok) {
348 console.error(`โŒ GitHub API error: ${response.status} ${response.statusText}`);
349
350 let errorText;
351 try {
352 errorText = await response.text();
353 console.error("โŒ GitHub API error response:", errorText);
354
355 try {
356 // Try to parse as JSON for more details
357 const errorJson = JSON.parse(errorText);
358 console.error("โŒ GitHub API error details:", JSON.stringify(errorJson));
359 } catch (e) {
360 // Not JSON, that's fine
370 try {
371 data = await response.json();
372 console.log("๐Ÿ” Successfully parsed GitHub API response");
373 } catch (jsonError) {
374 console.error("โŒ Failed to parse GitHub API response:", jsonError);
375
376 try {
384 }
385
386 throw new Error(`Failed to parse GitHub API response: ${jsonError.message}`);
387 }
388
400}
401
402// Merge a PR via GitHub API
403async function mergePR(repo: string, prNumber: number) {
404 console.log(`๐Ÿ” Starting mergePR for PR #${prNumber} in ${repo}`);
448
449 // Proceed with merge
450 const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}/merge`;
451 console.log("๐Ÿ” Sending merge request to:", url);
452
468 body: mergeBody,
469 });
470 console.log("๐Ÿ” Merge API response received");
471 console.log("๐Ÿ” Response status:", response.status);
472 console.log("๐Ÿ” Response status text:", response.statusText);
638 body: JSON.stringify(message),
639 });
640 console.log("๐Ÿ” Slack API response received");
641 console.log("๐Ÿ” Response status:", response.status);
642 console.log("๐Ÿ” Response status text:", response.statusText);
649
650 if (!response.ok) {
651 console.error(`โŒ Slack API error: ${response.status} ${response.statusText}`);
652
653 let errorText;
654 try {
655 errorText = await response.text();
656 console.error("โŒ Slack API error response:", errorText);
657 } catch (e) {
658 console.error("โŒ Could not read error response:", e);
198 }
199
200 const url = `https://api.github.com/repos/${repo}/issues/${issueNumber}`;
201 console.log("๐Ÿ” Fetching issue from:", url);
202
209 });
210
211 console.log("๐Ÿ” GitHub API response status:", response.status);
212
213 if (!response.ok) {
215 try {
216 const error = await response.json();
217 console.error("โŒ GitHub API error:", JSON.stringify(error));
218 errorMessage = error.message || errorMessage;
219 } catch (e) {
220 const errorText = await response.text();
221 console.error("โŒ GitHub API error text:", errorText);
222 }
223 throw new Error(`Failed to fetch issue: ${errorMessage}`);
237
238 try {
239 const url = `https://api.github.com/repos/${repo}/issues/${prNumber}/labels`;
240 console.log("๐Ÿ” Sending labels update request to:", url);
241
253 });
254
255 console.log("๐Ÿ” GitHub API response status:", response.status);
256
257 if (response.ok) {
264 try {
265 const error = await response.json();
266 console.error("โŒ GitHub API error:", JSON.stringify(error));
267 errorMessage = error.message || errorMessage;
268 } catch (e) {
269 const errorText = await response.text();
270 console.error("โŒ GitHub API error text:", errorText);
271 }
272 return { success: false, message: errorMessage };
273 }
274 } catch (error) {
275 console.error("โŒ Exception during API call:", error);
276 return { success: false, message: error.message };
277 }
163
164 try {
165 const url = `https://api.github.com/repos/${repo}/pulls/${prNumber}`;
166 console.log("๐Ÿ” Sending title update request to:", url);
167
179 });
180
181 console.log("๐Ÿ” GitHub API response status:", response.status);
182
183 if (response.ok) {
189 try {
190 const error = await response.json();
191 console.error("โŒ GitHub API error:", JSON.stringify(error));
192 errorMessage = error.message || errorMessage;
193 } catch (e) {
194 const errorText = await response.text();
195 console.error("โŒ GitHub API error text:", errorText);
196 }
197 return { success: false, message: errorMessage };
198 }
199 } catch (error) {
200 console.error("โŒ Exception during API call:", error);
201 return { success: false, message: error.message };
202 }

realtimemain.js5 matches

@emarrefโ€ขUpdated 1 day ago
5// โ—โ—โ— DO NOT USE YOUR TOKEN IN THE BROWSER FOR PRODUCTION. It should be kept and used server-side.
6const APP_TOKEN = process.env.APP_TOKEN;
7// We'll use this for authentication when making requests to the Calls API.
8const headers = {
9 Authorization: `Bearer ${APP_TOKEN}`,
10};
11const API_BASE = `https://rtc.live.cloudflare.com/v1/apps/${APP_ID}`;
12
13const echoMagic = crypto.randomUUID();
21
22const channel1resp = await fetch(
23 `${API_BASE}/sessions/${session1.sessionId}/datachannels/new`,
24 {
25 method: "POST",
45
46const channel1SubscribeResp = await fetch(
47 `${API_BASE}/sessions/${session2.sessionId}/datachannels/new`,
48 {
49 method: "POST",
136 );
137 const { sessionId, sessionDescription } = await fetch(
138 `${API_BASE}/sessions/new`,
139 {
140 method: "POST",

blob_adminmain.tsx6 matches

@wolfโ€ขUpdated 1 day ago
14
15// Public route without authentication
16app.get("/api/public/:id", async (c) => {
17 const key = `__public/${c.req.param("id")}`;
18 const { blob } = await import("https://esm.town/v/std/blob");
132};
133
134app.get("/api/blobs", checkAuth, async (c) => {
135 const prefix = c.req.query("prefix") || "";
136 const limit = parseInt(c.req.query("limit") || "20", 10);
141});
142
143app.get("/api/blob", checkAuth, async (c) => {
144 const key = c.req.query("key");
145 if (!key) return c.text("Missing key parameter", 400);
149});
150
151app.put("/api/blob", checkAuth, async (c) => {
152 const key = c.req.query("key");
153 if (!key) return c.text("Missing key parameter", 400);
158});
159
160app.delete("/api/blob", checkAuth, async (c) => {
161 const key = c.req.query("key");
162 if (!key) return c.text("Missing key parameter", 400);
166});
167
168app.post("/api/blob", checkAuth, async (c) => {
169 const { file, key } = await c.req.parseBody();
170 if (!file || !key) return c.text("Missing file or key", 400);

blob_adminapp.tsx19 matches

@wolfโ€ขUpdated 1 day ago
70 const menuRef = useRef(null);
71 const isPublic = blob.key.startsWith("__public/");
72 const publicUrl = isPublic ? `${window.location.origin}/api/public/${encodeURIComponent(blob.key.slice(9))}` : null;
73
74 useEffect(() => {
234 setLoading(true);
235 try {
236 const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237 const data = await response.json();
238 setBlobs(data);
261 setBlobContentLoading(true);
262 try {
263 const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264 const content = await response.text();
265 setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
275 const handleSave = async () => {
276 try {
277 await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278 method: "PUT",
279 body: editContent,
287 const handleDelete = async (key) => {
288 try {
289 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290 setBlobs(blobs.filter(b => b.key !== key));
291 if (selectedBlob && selectedBlob.key === key) {
304 const key = `${searchPrefix}${file.name}`;
305 formData.append("key", encodeKey(key));
306 await fetch("/api/blob", { method: "POST", body: formData });
307 const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308 setBlobs([newBlob, ...blobs]);
326 try {
327 const fullKey = `${searchPrefix}${key}`;
328 await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329 method: "PUT",
330 body: "",
341 const handleDownload = async (key) => {
342 try {
343 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344 const blob = await response.blob();
345 const url = window.URL.createObjectURL(blob);
360 if (newKey && newKey !== oldKey) {
361 try {
362 const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363 const content = await response.blob();
364 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365 method: "PUT",
366 body: content,
367 });
368 await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369 setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370 if (selectedBlob && selectedBlob.key === oldKey) {
380 const newKey = `__public/${key}`;
381 try {
382 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383 const content = await response.blob();
384 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385 method: "PUT",
386 body: content,
387 });
388 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389 setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390 if (selectedBlob && selectedBlob.key === key) {
399 const newKey = key.slice(9); // Remove "__public/" prefix
400 try {
401 const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402 const content = await response.blob();
403 await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404 method: "PUT",
405 body: content,
406 });
407 await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408 setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409 if (selectedBlob && selectedBlob.key === key) {
554 onClick={() =>
555 copyToClipboard(
556 `${window.location.origin}/api/public/${encodeURIComponent(selectedBlob.key.slice(9))}`,
557 )}
558 className="text-blue-400 hover:text-blue-300 text-sm"
577 >
578 <img
579 src={`/api/blob?key=${encodeKey(selectedBlob.key)}`}
580 alt="Blob content"
581 className="max-w-full h-auto"

TownieLoginRoute.tsx8 matches

@valdottownโ€ขUpdated 1 day ago
8 const { isAuthenticated, authenticate, error } = useAuth();
9 const [tokenValue, setTokenValue] = useState("");
10 const [apiKey, setApiKey] = useState("");
11 // const [invalid, setInvalid] = useState(""); // TODO
12
13 const handleSubmit = (e) => {
14 e.preventDefault();
15 authenticate(tokenValue, apiKey);
16 };
17
36 >
37 <div>
38 <label htmlFor="valtown-token" className="label">Val Town API Token</label>
39 <div style={{ fontSize: "0.8em", color: "#666" }}>
40 <p>
41 <a href="https://www.val.town/settings/api/new" target="_blank" rel="noreferrer">
42 Create a Val Town token here
43 </a>
58 </div>
59 <div>
60 <label htmlFor="anthropic-api-key" className="label">Anthropic API Key (optional)</label>
61 <input
62 type="password"
63 id="anthropic-api-key"
64 name="anthropic-key"
65 value={apiKey}
66 onChange={e => {
67 setApiKey(e.target.value);
68 }}
69 />

telegramBotStartersendTelegramMessage.tsx4 matches

@asdfgโ€ขUpdated 1 day ago
1/**
2 * Sends a message to a Telegram chat via the Telegram Bot API
3 * Requires a Telegram Bot token as an environment variable
4 */
10 }
11
12 const telegramApiUrl = `https://api.telegram.org/bot${botToken}/sendMessage`;
13
14 const response = await fetch(telegramApiUrl, {
15 method: 'POST',
16 headers: {
25 if (!response.ok) {
26 const errorBody = await response.text();
27 throw new Error(`Telegram API error: ${response.status} ${errorBody}`);
28 }
29

telegramBotStarterwebhookInfo.tsx1 match

@asdfgโ€ขUpdated 1 day ago
6 const botToken = process.env.TELEGRAM_BOT_TOKEN;
7
8 const response = await fetch(`https://api.telegram.org/bot${botToken}/getWebhookInfo`);
9 const result = await response.json();
10 return result;

blob_adminmain.tsx6 matches

@fredmoonโ€ขUpdated 1 day ago
14
15// Public route without authentication
16app.get("/api/public/:id", async (c) => {
17 const key = `__public/${c.req.param("id")}`;
18 const { blob } = await import("https://esm.town/v/std/blob");
132};
133
134app.get("/api/blobs", checkAuth, async (c) => {
135 const prefix = c.req.query("prefix") || "";
136 const limit = parseInt(c.req.query("limit") || "20", 10);
141});
142
143app.get("/api/blob", checkAuth, async (c) => {
144 const key = c.req.query("key");
145 if (!key) return c.text("Missing key parameter", 400);
149});
150
151app.put("/api/blob", checkAuth, async (c) => {
152 const key = c.req.query("key");
153 if (!key) return c.text("Missing key parameter", 400);
158});
159
160app.delete("/api/blob", checkAuth, async (c) => {
161 const key = c.req.query("key");
162 if (!key) return c.text("Missing key parameter", 400);
166});
167
168app.post("/api/blob", checkAuth, async (c) => {
169 const { file, key } = await c.req.parseBody();
170 if (!file || !key) return c.text("Missing file or key", 400);

new-val-api-21 file match

@shouserโ€ขUpdated 20 hours ago
This is an example of using the API to create a val.

gptApiTemplate2 file matches

@charmaineโ€ขUpdated 2 days ago
mux
Your friendly, neighborhood video API.
api