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=api&page=271&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 12051 results for "api"(1203ms)

stevensDemo_1generateFunFacts.ts6 matches

@Suqi0626•Updated 3 weeks ago
2import { nanoid } from "https://esm.sh/nanoid@5.0.5";
3import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
4import { Configuration, OpenAIApi } from "npm:openai";
5
6const TABLE_NAME = `memories`;
77async function generateFunFacts(previousFacts) {
78 try {
79 const apiKey = Deno.env.get("OPENAI_API_KEY");
80 if (!apiKey) {
81 console.error("OpenAI API key is not configured.");
82 return null;
83 }
84
85 const configuration = new Configuration({ apiKey });
86 const openai = new OpenAIApi(configuration);
87
88 const previousFactsText = previousFacts

blob_adminmain.tsx6 matches

@slimneo•Updated 3 weeks ago
15
16// Public route without authentication
17app.get("/api/public/:id", async (c) => {
18 const key = `__public/${c.req.param("id")}`;
19 const { blob } = await import("https://esm.town/v/std/blob");
133};
134
135app.get("/api/blobs", checkAuth, async (c) => {
136 const prefix = c.req.query("prefix") || "";
137 const limit = parseInt(c.req.query("limit") || "20", 10);
142});
143
144app.get("/api/blob", checkAuth, async (c) => {
145 const key = c.req.query("key");
146 if (!key) return c.text("Missing key parameter", 400);
150});
151
152app.put("/api/blob", checkAuth, async (c) => {
153 const key = c.req.query("key");
154 if (!key) return c.text("Missing key parameter", 400);
159});
160
161app.delete("/api/blob", checkAuth, async (c) => {
162 const key = c.req.query("key");
163 if (!key) return c.text("Missing key parameter", 400);
167});
168
169app.post("/api/blob", checkAuth, async (c) => {
170 const { file, key } = await c.req.parseBody();
171 if (!file || !key) return c.text("Missing file or key", 400);

blob_adminapp.tsx19 matches

@slimneo•Updated 3 weeks 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"

e424b5getEdgarFilings1 match

@xpipko•Updated 3 weeks ago
109
110 if (!response.ok) {
111 throw new Error(`SEC API error: ${response.status} ${response.statusText}`);
112 }
113

stevensDemoREADME.md5 matches

@vilozio•Updated 3 weeks ago
8## Hono
9
10This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
11
12## Serving assets to the frontend
20### `index.html`
21
22The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
23
24We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
25
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors
31
32Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.

FarcasterSpacesHome.tsx2 matches

@moe•Updated 3 weeks ago
37
38function Spaces() {
39 const queryFn = () => fetch(`/api/channels`).then(r => r.json()).then(r => r?.data?.channels);
40 const { data: spaces } = useQuery({ queryKey: ["spaces"], queryFn });
41 console.log(spaces);
88 onChange={e => setChannel(e.target.value)}
89 placeholder="Space Title"
90 autoCapitalize="on"
91 autoCorrect="on"
92 type="text"

FarcasterSpacesneynar.ts2 matches

@moe•Updated 3 weeks ago
1const baseUrl = "/neynar-proxy?path=";
2// const baseUrl = "https://api.neynar.com/v2/farcaster/";
3
4export async function fetchNeynarGet(path: string) {
8 "Content-Type": "application/json",
9 "x-neynar-experimental": "true",
10 "x-api-key": "NEYNAR_API_DOCS",
11 },
12 });

FarcasterSpacesneynar.ts4 matches

@moe•Updated 3 weeks ago
1const NEYNAR_API_KEY = Deno.env.get("NEYNAR_API_KEY") || "NEYNAR_API_DOCS";
2const headers = {
3 "Content-Type": "application/json",
4 "x-api-key": NEYNAR_API_KEY,
5};
6
7export const fetchGet = async (path: string) => {
8 return await fetch("https://api.neynar.com/v2/farcaster/" + path, {
9 method: "GET",
10 headers: headers,
13
14export const fetchPost = async (path: string, body: any) => {
15 return await fetch("https://api.neynar.com/v2/farcaster/" + path, {
16 method: "POST",
17 headers: headers,

remark-frontmatter-starterithy-jiddu.md4 matches

@arfan•Updated 3 weeks ago
14## Discover the profound understandings of a philosopher who challenged humanity to break free from all conditioning.
15
16![jiddu-krishnamurti-understandings-philosophy-vxjotznj2e](https://storage.googleapis.com/e-object-409003.firebasestorage.app/jiddu-krishnamurti-understandings-philosophy-vxjotznj2e.jpg)
17
18*Jiddu Krishnamurti, a philosopher whose teachings emphasized direct perception and freedom.*
26---
27
28![Krishnamurti with Annie Besant](https://storage.googleapis.com/e-object-409003.firebasestorage.app/jiddu-krishnamurti-understandings-philosophy-vxjotznj2e-1.jpg)
29
30*Krishnamurti (right) during his early years with his mentor Annie Besant (left), a key figure in the Theosophical Society.*
47* **Immediacy of Truth:** Truth is not a distant goal to be achieved through time or practice, but a living reality to be perceived in the present moment, free from the distortions of the past or projections of the future.
48
49![Krishnamurti Order of the Star Dissolution Speech Document](https://storage.googleapis.com/e-object-409003.firebasestorage.app/jiddu-krishnamurti-understandings-philosophy-vxjotznj2e-2.jpg)
50
51*A visual representation related to Krishnamurti's historic 1929 speech where he declared "Truth is a pathless land."*
176The goal was not merely academic excellence but the emergence of mature, sensitive, intelligent human beings capable of living peacefully and creatively in a complex world.
177
178![Krishnamurti speaking with students](https://storage.googleapis.com/e-object-409003.firebasestorage.app/jiddu-krishnamurti-understandings-philosophy-vxjotznj2e-3.jpg)
179
180*Krishnamurti engaging in discussion, reflecting his emphasis on dialogue and inquiry in education.*

MyPersonalBotsendDailyBrief.ts8 matches

@lukashakkarainen•Updated 3 weeks ago
97
98export async function sendDailyBriefing(chatId?: string, today?: DateTime) {
99 // Get API keys from environment
100 const apiKey = Deno.env.get("ANTHROPIC_API_KEY");
101 const telegramToken = Deno.env.get("TELEGRAM_TOKEN");
102
106 }
107
108 if (!apiKey) {
109 console.error("Anthropic API key is not configured.");
110 return;
111 }
122
123 // Initialize Anthropic client
124 const anthropic = new Anthropic({ apiKey });
125
126 // Initialize Telegram bot
162
163 // disabled title for now, it seemes unnecessary...
164 // await bot.api.sendMessage(chatId, `*${title}*`, { parse_mode: "Markdown" });
165
166 // Then send the main content
169
170 if (content.length <= MAX_LENGTH) {
171 await bot.api.sendMessage(chatId, content, { parse_mode: "Markdown" });
172 // Store the briefing in chat history
173 await storeChatMessage(
198 // Send each chunk as a separate message and store in chat history
199 for (const chunk of chunks) {
200 await bot.api.sendMessage(chatId, chunk, { parse_mode: "Markdown" });
201 // Store each chunk in chat history
202 await storeChatMessage(

social_data_api_project3 file matches

@tsuchi_ya•Updated 1 day ago

simple-scrabble-api1 file match

@bry•Updated 4 days ago
apiv1
papimark21