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=570&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 11896 results for "api"(2353ms)

redditAlertREADME.md10 matches

@Ali12•Updated 2 months ago
72. Send notifications to your preferred platform (Discord, Slack, email, etc.)
8
9Reddit does not have an API that allows users to scrape data, so we are doing this with the Google Search API, [Serp](https://serpapi.com/).
10
11---
29
30---
31### 3. Get a SerpApi Key
32This template requires a [SerpApi](https://serpapi.com/) key to search Reddit posts via Google search results.
33
341. **Get a SerpApi key**:
35 - Sign up at [SerpApi](https://serpapi.com/) to create an account.
36 - Generate an API key from your account dashboard.
37
382. **Add the SerpApi key to your environment variables**:
39 - Go to your [Val Town environment variables](https://www.val.town/settings/environment-variables).
40 - Add a new key:
41 - Key: `SERP_API_KEY`
42 - Value: Your SERP API key.
43
44Without this key, the val will not function correctly.
75
76### NOTE: Usage Limits
77- **SerpApi:** Free SerpApi accounts have monthly call limits.

redditAlertmain.tsx9 matches

@Ali12•Updated 2 months ago
1import { searchWithSerpApi } from "https://esm.town/v/charmaine/searchWithSerpApi";
2import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook";
3
4// Customize your search parameters
5const KEYWORDS = "\"node\" OR \"node.js\"";
6const DISCORD_API_KEY = Deno.env.get("mentionsDiscord");
7const SERP_API_KEY = Deno.env.get("SERP_API_KEY");
8
9// Set isProd = false for testing and = true for production
13
14export async function redditAlert({ lastRunAt }: Interval) {
15 if (!SERP_API_KEY || !DISCORD_API_KEY) {
16 console.error("Missing SERP_API_KEY or Discord webhook URL. Exiting.");
17 return;
18 }
19
20 // Determine the time frame for the search
21 // Details on as_qdr: https://serpapi.com/advanced-google-query-parameters#api-parameters-advanced-search-query-parameters-as-qdr
22 const timeFrame = isProd
23 ? lastRunAt
27
28 try {
29 const response = await searchWithSerpApi({
30 query: KEYWORDS,
31 site: "reddit.com",
32 apiKey: SERP_API_KEY,
33 as_qdr: timeFrame,
34 });
62 if (isProd) {
63 await discordWebhook({
64 url: DISCORD_API_KEY,
65 content,
66 });

reactHonoExampleREADME.md5 matches

@varun1352•Updated 2 months 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.

redditKeywordSMSmain.tsx5 matches

@charmaine•Updated 2 months ago
1import { searchWithSerpApi } from "https://esm.town/v/charmaine/searchWithSerpApi";
2import sendSMS from "https://esm.town/v/charmaine/sendMessageWithTwilio";
3
11
12 // Get environment variables
13 const apiKey = Deno.env.get("SERP_API_KEY");
14 const twilioSid = Deno.env.get("TWILIO_ACCOUNT_SID");
15 const twilioToken = Deno.env.get("TWILIO_AUTH_TOKEN");
18
19 // Check if we have all required credentials
20 if (!apiKey || !twilioSid || !twilioToken || !fromNumber || !toNumber) {
21 console.error("Missing required environment variables");
22 return;
26 // Search for Reddit posts from the last week
27 console.log("Searching for Reddit posts...");
28 const posts = await searchWithSerpApi({
29 query: "\"val.town\" OR \"val.run\" OR \"val town\"",
30 site: "reddit.com",
31 apiKey,
32 as_qdr: "d7", // Get posts from the last week
33 });

memorableCoralCheetahmain.tsx8 matches

@charmaine•Updated 2 months ago
1import { searchWithSerpApi } from "https://esm.town/v/charmaine/searchWithSerpApi";
2import sendSMS from "https://esm.town/v/charmaine/sendMessageWithTwilio";
3
7
8 // Get environment variables
9 const apiKey = Deno.env.get("SERP_API_KEY");
10 const twilioSid = Deno.env.get("TWILIO_ACCOUNT_SID");
11 const twilioToken = Deno.env.get("TWILIO_AUTH_TOKEN");
14
15 // Check if we have all required credentials
16 if (!apiKey || !twilioSid || !twilioToken || !fromNumber || !toNumber) {
17 console.error("Missing required environment variables:", {
18 hasApiKey: !!apiKey,
19 hasTwilioSid: !!twilioSid,
20 hasTwilioToken: !!twilioToken,
29 try {
30 // Search for Reddit posts
31 console.log("Initiating SERP API search...");
32 const posts = await searchWithSerpApi({
33 query: "\"node\" OR \"node.js\"",
34 site: "reddit.com",
35 apiKey,
36 as_qdr: "d7", // Get posts from the last week
37 });
96 console.error("Error in Reddit Alert Test:", error);
97 if (error.response) {
98 console.error("API error response:", JSON.stringify(error.response.data || error.response, null, 2));
99 }
100 if (error.request) {

memorableCoralCheetahREADME.md2 matches

@charmaine•Updated 2 months ago
14- Twilio account (for SMS notifications)
15 - You can create an account with $15 free credits at https://www.twilio.com/ without putting in your credit card
16- SerpApi key (for searching Reddit)
17
18---
20**Customize all of these according to your preferences:**
21```
22 const apiKey = Deno.env.get("SERP_API_KEY");
23 const twilioSid = Deno.env.get("TWILIO_ACCOUNT_SID");
24 const twilioToken = Deno.env.get("TWILIO_AUTH_TOKEN");

unsplashSourceReimplementationREADME.md1 match

@charmaine•Updated 2 months ago
1Re-implements Unsplash Source which was a service hosted at source.unsplash.com that served random photos from Unsplash.
2
3To use this, you'll want to fork it, provide your own Unsplash API key, and configure the allowed domains.
4
5Read more: https://paul.af/reimplementing-unsplash-source

unsplashSourceReimplementationmain.tsx11 matches

@charmaine•Updated 2 months ago
1/**
2 * Unsplash API Random Photo Endpoint Implementation
3 * Generates random images using the official Unsplash API with caching
4 * Restricted to Val Town and specific origins
5 */
52 }
53
54 // Retrieve Unsplash API access key from environment
55 const UNSPLASH_ACCESS_KEY = Deno.env.get("UNSPLASH_ACCESS_KEY");
56
57 if (!UNSPLASH_ACCESS_KEY) {
58 return new Response("Unsplash API key not configured", { status: 500 });
59 }
60
165 "X-Unsplash-User": cachedResponse.username,
166 "X-Unsplash-Description": cachedResponse.description || "Random Unsplash Image",
167 "X-Powered-By": "Val Town Unsplash API",
168 "Link": `<${cachedResponse.originalLink}>; rel="describedby"`, // Updated link relation type
169 },
175 }
176
177 // Construct Unsplash API URL
178 const unsplashApiUrl = new URL("https://api.unsplash.com/photos/random");
179
180 // Add parameters conditionally
226
227 // Set the search params on the URL
228 unsplashApiUrl.search = searchParams.toString();
229
230 try {
231 const response = await fetch(unsplashApiUrl, {
232 headers: {
233 "Accept-Version": "v1",
239 // Include the response body for more detailed error information
240 const errorBody = await response.text();
241 return new Response(`Failed to fetch from Unsplash API: ${errorBody}`, { status: response.status });
242 }
243
276 "X-Unsplash-User": photo.user.username,
277 "X-Unsplash-Description": photo.description || "Random Unsplash Image",
278 "X-Powered-By": "Val Town Unsplash API",
279 "Link": `<${photo.links.html}>; rel="describedby"`, // Updated link relation type
280 },

resourcefulPurpleBobolinkmain.tsx1 match

@harsha_5870•Updated 2 months ago
250 <title>EcoAssist: Sustainable Living AI</title>
251 <meta name="viewport" content="width=device-width, initial-scale=1">
252 <link href="https://fonts.googleapis.com/css2?family=Segoe+UI:wght@300;400;700&display=swap" rel="stylesheet">
253 <style>
254 body {

reactHonoExampleREADME.md5 matches

@stevekrouse•Updated 2 months 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.

social_data_api_project3 file matches

@tsuchi_ya•Updated 1 day ago

simple-scrabble-api1 file match

@bry•Updated 1 day ago
apiv1
papimark21