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=api&page=31&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 20751 results for "api"(4268ms)

demo-voterindex.ts2 matches

@cricks_unmixed4u•Updated 3 days ago
77
78// Create new vote
79app.post("/api/votes", async (c) => {
80 const id = crypto.randomUUID();
81 const title = generateVoteTitle();
95
96// Get vote by ID
97app.get("/api/votes/:id", async (c) => {
98 const id = c.req.param("id");
99 const now = Date.now();

RichardhandleLocation.ts8 matches

@pcastronova•Updated 3 days ago
3 const { lat, lon } = await req.json();
4
5 const openCageKey = Deno.env.get("OPENCAGE_API_KEY");
6 const openAIKey = Deno.env.get("OPENAI_API_KEY");
7
8 if (!openCageKey || !openAIKey) {
9 return new Response(
10 JSON.stringify({ error: "API keys not set in environment variables." }),
11 { status: 500, headers: { "Content-Type": "application/json" } },
12 );
15 // Reverse geocode to get place name
16 const geoResp = await fetch(
17 `https://api.opencagedata.com/geocode/v1/json?q=${lat}+${lon}&key=${openCageKey}`,
18 );
19 const geoData = await geoResp.json();
22 // Get Wikipedia summary for the place
23 const wikiResp = await fetch(
24 `https://en.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(placeName)}`,
25 );
26 const wikiData = await wikiResp.json();
31 `You are Richard Ayoade from Travel Man. Write a short, dry, funny fact about this place:\n\nLocation: ${placeName}\nFact: ${summary}`;
32
33 // Call OpenAI API for witty fact
34 const openaiResp = await fetch("https://api.openai.com/v1/chat/completions", {
35 method: "POST",
36 headers: {
47 const errorText = await openaiResp.text();
48 return new Response(
49 JSON.stringify({ error: `OpenAI API error: ${errorText}` }),
50 { status: 500, headers: { "Content-Type": "application/json" } },
51 );

GetRamiLevySearchmain.tsx2 matches

@binikingi•Updated 3 days ago
3export default async function(req: Request): Promise<Response> {
4 if (req.method.toLowerCase() !== "post") {
5 const response = await axios.post("https://www.rami-levy.co.il/api/catalog", {
6 q: "8000380004911",
7 aggs: 1,
32 }
33 const { barcode } = await req.json() as { barcode: string };
34 const response = await axios.post("https://www.rami-levy.co.il/api/catalog", {
35 q: barcode,
36 aggs: 1,

demo-voterknowledge.md14 matches

@cricks_unmixed4u•Updated 3 days ago
14- Generate code in TypeScript or TSX
15- Add appropriate TypeScript types and interfaces for all data structures
16- Prefer official SDKs or libraries than writing API calls directly
17- Ask the user to supply API or library documentation if you are at all unsure about it
18- **Never bake in secrets into the code** - always use environment variables
19- Include comments explaining complex logic (avoid commenting obvious operations)
24### 1. HTTP Trigger
25
26- Create web APIs and endpoints
27- Handle HTTP requests and responses
28- Example structure:
135## GreenPTClient
136
137The `GreenPTClient` is a function that allows interaction with the GreenPT API for chat completions. It accepts a model parameter and provides an `invoke` method to send messages and retrieve responses asynchronously. To ensure API security, it requires an API key stored in environment variables.
138
139### Example Usage
146async function getChatResponse() {
147 const messages = [
148 { role: "user", content: "What is the capital of France?" },
149 ];
150
153 console.log("AI Response:", response);
154 } catch (error) {
155 console.error("Error invoking GreenPT API:", error);
156 }
157}
161```
162
163In this example, we create an instance of `GreenPTClient`, send a message asking about the capital of France, and log the AI's response. Error handling is included to catch any issues with the API call.
164
165### Email
228However, it's *extremely importing* to note that `parseProject` and other Standard Library utilities ONLY RUN ON THE SERVER.
229If 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
230or by making an API request for it.
231
232## Val Town Platform Specifics
236- **AI Image:** To inline generate an AI image use: `<img src="https://maxm-imggenurl.web.val.run/the-description-of-your-image" />`
237- **Storage:** DO NOT use the Deno KV module for storage
238- **Browser APIs:** DO NOT use the `alert()`, `prompt()`, or `confirm()` methods
239- **Weather Data:** Use open-meteo for weather data (doesn't require API keys) unless otherwise specified
240- **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
241- **Error Debugging:** Add `<script src="https://esm.town/v/std/catch"></script>` to HTML to capture client-side errors
242- **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
243- **Environment Variables:** Use `Deno.env.get('keyname')` when you need to, but generally prefer APIs that don't require keys
244- **Imports:** Use `https://esm.sh` for npm and Deno dependencies to ensure compatibility on server and browser
245- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites
279### Backend (Hono) Best Practices
280
281- Hono is the recommended API framework
282- Main entry point should be `backend/index.ts`
283- **Static asset serving:** Use the utility functions to read and serve project files:
303 });
304 ```
305- Create RESTful API routes for CRUD operations
306- Always include this snippet at the top-level Hono app to re-throwing errors to see full stack traces:
307 ```ts
340 - For files in the project, use `readFile` helpers
341
3425. **API Design:**
343 - `fetch` handler is the entry point for HTTP vals
344 - Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`

demo-voterREADME.md4 matches

@cricks_unmixed4u•Updated 3 days ago
13
14- **Frontend**: React with React Query for state management
15- **Backend**: Hono API framework
16- **Database**: SQLite for data persistence
17- **Styling**: TailwindCSS
26Example: "Amsterdam sustainable platform"
27
28## API Endpoints
29
30- `POST /api/votes` - Create a new vote
31- `GET /api/votes/:id` - Get vote by ID
32
33## Data Persistence

demo-voterVotePage.tsx1 match

@cricks_unmixed4u•Updated 3 days ago
19 queryKey: ["vote", voteId],
20 queryFn: async (): Promise<Vote> => {
21 const response = await fetch(`/api/votes/${voteId}`);
22
23 if (!response.ok) {

demo-voterCreateVote.tsx1 match

@cricks_unmixed4u•Updated 3 days ago
16 const createVoteMutation = useMutation({
17 mutationFn: async (): Promise<VoteResponse> => {
18 const response = await fetch("/api/votes", {
19 method: "POST",
20 headers: {

demo-voteropenai-client.mdc2 matches

@cricks_unmixed4u•Updated 4 days ago
15Use GlobalRateLimitedChatOpenAI(model, requestsPerSecond) to enforce a global rate limit on chat completions, suitable for shared or public-facing endpoints.
16Val Town/Platform Notes
17Uses Val Town’s standard SQLite API for persistent storage.
18Designed for server-side use (no browser-specific code).
19No secrets are hardcoded; OpenAI API keys are managed by the OpenAI SDK/environment.

demo-voter.cursorrules10 matches

@cricks_unmixed4u•Updated 4 days 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`

client-generatorREADME.md4 matches

@cricks_unmixed4u•Updated 4 days ago
1# GPT Wrapper Interface
2
3A Val Town project that provides a web interface for interacting with the GreenPT API through a statically imported GPT wrapper.
4
5## Project Structure
325. View the AI response
33
34## API Endpoints
35
36- `GET /` - Main web interface
37- `GET /gpt` - API information
38- `POST /gpt` - Send messages to GPT model
39
53This project demonstrates:
54- Static importing of external Val Town modules
55- Hono framework for API routing
56- Val Town utility functions for file serving
57- Clean separation of frontend and backend code

claude-api1 file match

@ziyanwould•Updated 3 days ago

api-workshop

@danarddanielsjr•Updated 4 days ago
replicate
Run AI with an API
fiberplane
Purveyors of Hono tooling, API Playground enthusiasts, and creators of 🪿 HONC 🪿 (https://honc.dev)