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=181&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 15070 results for "api"(970ms)

Townieindex.ts3 matches

@mickydziโ€ขUpdated 1 week ago
42);
43
44// token middleware for API requests
45app.all("/api/*", async (c, next) => {
46 const sessionCookie = getCookie(c, "_session");
47 if (!sessionCookie) {
53});
54
55app.route("/api", backend);
56
57app.get("/frontend/*", (c) => {

Townieindex.ts7 matches

@mickydziโ€ขUpdated 1 week ago
1import { basicAuthMiddleware } from "./auth.ts";
2import { handleApiRequest } from "./api/index.ts";
3import { getRequests } from "./api/requests.ts";
4import { getUserSummary } from "./api/user-summary.ts";
5import { getInferenceCalls } from "./api/inference-calls.ts";
6import { renderDashboard } from "./views/dashboard.ts";
7import { renderRequests } from "./views/requests.ts";
22 const path = url.pathname;
23
24 // Handle API requests
25 if (path.startsWith("/api/")) {
26 return handleApiRequest(req);
27 }
28

Townieindex.ts5 matches

@mickydziโ€ขUpdated 1 week ago
4
5/**
6 * Handle API requests
7 */
8export async function handleApiRequest(req: Request): Promise<Response> {
9 const url = new URL(req.url);
10 const path = url.pathname.replace("/api/", "");
11
12 try {
13 // Route to the appropriate API handler
14 if (path === "requests") {
15 const usageId = url.searchParams.get("usage_id");
59 }
60 } catch (error) {
61 console.error("API error:", error);
62 return new Response(JSON.stringify({ error: error.message }), {
63 status: 500,

TownieHome.tsx6 matches

@mickydziโ€ขUpdated 1 week ago
38 <ol>
39 <li>
40 Login with your Val Town API token (with projects:read,
41 projects:write, user:read permissions)
42 </li>
77 </div>
78 <h3>Cost Tracking</h3>
79 <p>See estimated API usage costs for each interaction</p>
80 </div>
81 </section>
86 <ul>
87 <li>React frontend with TypeScript</li>
88 <li>Hono API server backend</li>
89 <li>Web Audio API for sound notifications</li>
90 <li>AI SDK for Claude integration</li>
91 </ul>
92 <p>
93 The application proxies requests to the Anthropic API and Val Town
94 API, allowing Claude to view and edit your project files directly.
95 </p>
96 <div>

Townie.cursorrules10 matches

@mickydziโ€ขUpdated 1 week ago
13- Generate code in TypeScript or TSX
14- Add appropriate TypeScript types and interfaces for all data structures
15- Prefer official SDKs or libraries than writing API calls directly
16- Ask the user to supply API or library documentation if you are at all unsure about it
17- **Never bake in secrets into the code** - always use environment variables
18- Include comments explaining complex logic (avoid commenting obvious operations)
23### 1. HTTP Trigger
24
25- Create web APIs and endpoints
26- Handle HTTP requests and responses
27- Example structure:
173However, it's *extremely importing* to note that `parseProject` and other Standard Library utilities ONLY RUN ON THE SERVER.
174If you need access to this data on the client, run it in the server and pass it to the client by splicing it into the HTML page
175or by making an API request for it.
176
177## Val Town Platform Specifics
181- **AI Image:** To inline generate an AI image use: `<img src="https://maxm-imggenurl.web.val.run/the-description-of-your-image" />`
182- **Storage:** DO NOT use the Deno KV module for storage
183- **Browser APIs:** DO NOT use the `alert()`, `prompt()`, or `confirm()` methods
184- **Weather Data:** Use open-meteo for weather data (doesn't require API keys) unless otherwise specified
185- **View Source:** Add a view source link by importing & using `import.meta.url.replace("ems.sh", "val.town)"` (or passing this data to the client) and include `target="_top"` attribute
186- **Error Debugging:** Add `<script src="https://esm.town/v/std/catch"></script>` to HTML to capture client-side errors
187- **Error Handling:** Only use try...catch when there's a clear local resolution; Avoid catches that merely log or return 500s. Let errors bubble up with full context
188- **Environment Variables:** Use `Deno.env.get('keyname')` when you need to, but generally prefer APIs that don't require keys
189- **Imports:** Use `https://esm.sh` for npm and Deno dependencies to ensure compatibility on server and browser
190- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites
224### Backend (Hono) Best Practices
225
226- Hono is the recommended API framework
227- Main entry point should be `backend/index.ts`
228- **Static asset serving:** Use the utility functions to read and serve project files:
248 });
249 ```
250- Create RESTful API routes for CRUD operations
251- Always include this snippet at the top-level Hono app to re-throwing errors to see full stack traces:
252 ```ts
285 - For files in the project, use `readFile` helpers
286
2875. **API Design:**
288 - `fetch` handler is the entry point for HTTP vals
289 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`

Glideropsindex.tsx2 matches

@jasonrโ€ขUpdated 1 week ago
8 interface Window {
9 __INITIAL_DATA__: {
10 apiUrl: string;
11 projectInfo: {
12 name: string;
25 <React.StrictMode>
26 <App
27 apiUrl={window.__INITIAL_DATA__?.apiUrl || "/api"}
28 projectInfo={window.__INITIAL_DATA__?.projectInfo || { name: "Glider Tow Operation", version: "1.0.0" }}
29 />

Glideropsweather.ts10 matches

@jasonrโ€ขUpdated 1 week ago
10 const longitude = Deno.env.get("AIRFIELD_LONGITUDE") || "-122.0795";
11
12 // Fetch weather data from Open-Meteo API (no API key required)
13 const response = await fetch(
14 `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&current=temperature_2m,relative_humidity_2m,apparent_temperature,precipitation,rain,weather_code,cloud_cover,pressure_msl,surface_pressure,wind_speed_10m,wind_direction_10m,wind_gusts_10m&wind_speed_unit=mph&temperature_unit=fahrenheit`
15 );
16
17 if (!response.ok) {
18 throw new Error(`Weather API returned ${response.status}: ${response.statusText}`);
19 }
20
133 const longitude = Deno.env.get("AIRFIELD_LONGITUDE") || "-122.0795";
134
135 // Fetch forecast data from Open-Meteo API
136 const response = await fetch(
137 `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&daily=weather_code,temperature_2m_max,temperature_2m_min,sunrise,sunset,precipitation_sum,precipitation_hours,wind_speed_10m_max,wind_gusts_10m_max,wind_direction_10m_dominant&wind_speed_unit=mph&temperature_unit=fahrenheit&forecast_days=7`
138 );
139
140 if (!response.ok) {
141 throw new Error(`Weather API returned ${response.status}: ${response.statusText}`);
142 }
143
256 const airport = c.req.query("airport") || "KPAO"; // Default to Palo Alto Airport
257
258 // Fetch METAR data from Aviation Weather Center API
259 const metarResponse = await fetch(
260 `https://aviationweather.gov/api/data/metar?ids=${airport}&format=json`
261 );
262
263 if (!metarResponse.ok) {
264 throw new Error(`METAR API returned ${metarResponse.status}: ${metarResponse.statusText}`);
265 }
266
269 // Fetch TAF data
270 const tafResponse = await fetch(
271 `https://aviationweather.gov/api/data/taf?ids=${airport}&format=json`
272 );
273

happinessregistrationportalindex.ts4 matches

@seipatiannah1โ€ขUpdated 1 week ago
28});
29
30// API routes
31app.route("/api/auth", authRoutes);
32app.route("/api/children", childrenRoutes);
33app.route("/api/policies", policiesRoutes);
34
35// Static routes (must be last)

happinessregistrationportalapp.js9 matches

@seipatiannah1โ€ขUpdated 1 week ago
37};
38
39// API Base URL
40const API_BASE_URL = '/api';
41
42// Routes
77 if (token) {
78 try {
79 const response = await fetch(`${API_BASE_URL}/auth/me`, {
80 headers: {
81 'Authorization': `Bearer ${token}`
111 const token = localStorage.getItem('token');
112
113 const response = await fetch(`${API_BASE_URL}/children/my-children`, {
114 headers: {
115 'Authorization': `Bearer ${token}`
133 const token = localStorage.getItem('token');
134
135 const response = await fetch(`${API_BASE_URL}/policies/acceptance`, {
136 headers: {
137 'Authorization': `Bearer ${token}`
292
293 try {
294 const response = await fetch(`${API_BASE_URL}/auth/login`, {
295 method: 'POST',
296 headers: {
364
365 try {
366 const response = await fetch(`${API_BASE_URL}/auth/register`, {
367 method: 'POST',
368 headers: {
484 const token = localStorage.getItem('token');
485
486 const response = await fetch(`${API_BASE_URL}/children`, {
487 method: 'POST',
488 headers: {
568 const token = localStorage.getItem('token');
569
570 const response = await fetch(`${API_BASE_URL}/policies/acceptance`, {
571 method: 'POST',
572 headers: {
33โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
34โ”‚ โ”‚ โ””โ”€โ”€ queries.ts # DB query functions
35โ”‚ โ”œโ”€โ”€ routes/ # API routes
36โ”‚ โ”‚ โ”œโ”€โ”€ auth.ts # Authentication routes
37โ”‚ โ”‚ โ”œโ”€โ”€ children.ts # Child management routes

HN-fetch-call2 file matches

@ImGqbโ€ขUpdated 5 hours ago
fetch HackerNews by API

token-server1 file match

@kwhinnery_openaiโ€ขUpdated 1 day ago
Mint tokens to use with the OpenAI Realtime API for WebRTC
rapilot330
Kapil01