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=524&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 6292 results for "api"(726ms)

lastloginREADME.md1 match

@stevekrouse•Updated 8 months ago
4
5[LastLogin](https://lastlogin.io/) is a decentralized hosted auth provider
6that enables login to any app through email, Google, Github, etc without API keys.
7
8This val exports middleware that can be added to any HTTP val.

currencymain.tsx2 matches

@maraoz•Updated 8 months ago
2
3export let currency = async (desired, base = "usd", amount = 1) => {
4 let { rates } = await fetchJSON(`https://open.er-api.com/v6/latest/${base}`);
5 if (rates && rates[desired.toUpperCase()]) return amount * (rates[desired.toUpperCase()]);
6 else {
7 let { rates } = await fetchJSON(
8 `https://api.coingecko.com/api/v3/exchange_rates?&x_cg_demo_api_key=${Deno.env.get("COINGECKO_API_KEY")}`,
9 );
10 return amount * rates[desired.toLowerCase()]?.value / rates[base.toLowerCase()]?.value;

VALLErunmain.tsx11 matches

@janpaul123•Updated 8 months ago
211 Make an HTTP val (other vals are currently not supported to run, even though we have examples for them).
212 Start your response with a comment explaining how your approach will work, what libraries or
213 API calls you will use, and any tradeoffs you're making. Then write the code in a consise way,
214 the simplest way to achieve the goal, though you can add some inline comments to explain your
215 reasoning (not for every line, but for major groups of lines). Don't use any environment variables
216 unless strictly necessary, for example use APIs that don't require a key, prefer internal function
217 imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
218 functions where possible. Unless specified, don't add error handling,
219 make sure that errors bubble up to the caller.
220 Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
221 not practical for the user's request (e.g. if they ask for a particular animated gif).
222 If the user asks for something that requires persistence, use the Val Town Blob storage API, unless
223 explicitly specified otherwise. Use the current val name for the storage key, which you can get
224 using the "pomdtr/extractValInfo" val, which you can call like this:
273Make an HTTP val (other vals are currently not supported to run, even though we have examples for them).
274Add comments at the top of the file explaining how your approach works, what libraries or
275API calls you will use, and any tradeoffs you're making. Then write the code in a consise way,
276the simplest way to achieve the goal, though you can add some inline comments to explain your
277reasoning (not for every line, but for major groups of lines). Don't use any environment variables
278unless strictly necessary, for example use APIs that don't require a key, prefer internal function
279imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
280functions where possible. Unless specified, don't add error handling,
281make sure that errors bubble up to the caller.
282Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
283not practical for the user's request (e.g. if they ask for a particular animated gif).
284If the user asks for something that requires persistence, use the Val Town Blob storage API, unless
285explicitly specified otherwise. Use the current val name for the storage key, which you can get
286using the "pomdtr/extractValInfo" val, which you can call like this:
389 \`\`\`
390
391 ### Lower-level API
392
393 We do provide access to the lower-level getter and setters, which are useful if you are storing non-JSON or binary data, need to stream in your response or request data, or do anything else lower-level.
394
395 - \`async get(key: string)\`: Retrieves a blob for a given key.
396 - \`async set(key: string, value: string | BodyInit)\`: Sets the blob value for a given key. See [BodyInit](https://deno.land/api@v1.38.1?s=BodyInit).
397
398 ### Limitations
1204
1205 const tempValName = `valle_tmp_${Math.random() * 10}`.replaceAll(".", "");
1206 // Errors in running the val bubble up through this API, so ignore them.
1207 await vt.vals.create({ name: tempValName, code: newCode, type: "http" as any, privacy: "unlisted" }).catch(
1208 (error) => {

resyAuthmain.tsx3 matches

@stevekrouse•Updated 8 months ago
1import { fetch } from "https://esm.town/v/std/fetch";
2import { resyPublicAPIKey } from "https://esm.town/v/vtdocs/resyPublicAPIKey";
3
4export const resyAuth = async (email: string, password: string): Promise<{
9 }[];
10}> => {
11 const authRes = await fetch("https://api.resy.com/3/auth/password", {
12 "headers": {
13 "authorization":
14 `ResyAPI api_key="${resyPublicAPIKey}"`,
15 "content-type": "application/x-www-form-urlencoded",
16 },

valleGetValsContextWindowmain.tsx7 matches

@janpaul123•Updated 8 months ago
13 const readmeVals: any = await (await fetch("https://janpaul123-readmevals.web.val.run/")).json();
14
15 const API_URL = "https://api.val.town";
16
17 const sections = [
129 {
130 prompt: "Write a val that accesses environment variables",
131 code: `const res = await fetch("${API_URL}/v1/me", {
132 headers: {
133 Authorization: \`Bearer \${Deno.env.get("valtown")}\`,
141 code: `import process from "node:process";
142
143 const res = await fetch("${API_URL}/v1/me", {
144 headers: {
145 Authorization: \`Bearer \${process.env.valtown}\`,
310 You can attach files to your emails by using the \`attachments\` field.
311 Attachments need to be [Base64](https://en.wikipedia.org/wiki/Base64) encoded,
312 which is that the [btoa](https://developer.mozilla.org/en-US/docs/Web/API/btoa)
313 method is doing in this example:
314
412 \`\`\`
413
414 ### Lower-level API
415
416 We do provide access to the lower-level getter and setters, which are useful if you are storing non-JSON or binary data, need to stream in your response or request data, or do anything else lower-level.
417
418 - \`async get(key: string)\`: Retrieves a blob for a given key.
419 - \`async set(key: string, value: string | BodyInit)\`: Sets the blob value for a given key. See [BodyInit](https://deno.land/api@v1.38.1?s=BodyInit).
420
421 ### Limitations
458 role: "assistant",
459 content:
460 "```ts\nexport default async function(req: Request): Promise<Response> {\n const apiKey = Deno.env.get(\"METEO_KEY\");\n const apiUrl = `https://api.open-meteo.com/v1/forecast?latitude=40.6782&longitude=-73.9442&hourly=temperature_2m&current_weather=true&apikey=${apiKey}`;\n\n const response = await fetch(apiUrl);\n const weatherData = await response.json();\n\n return new Response(JSON.stringify(weatherData), { headers: { \"Content-Type\": \"application/json\" } });\n}\n```",
461 },
462 {

valleBlogV0README.md1 match

@janpaul123•Updated 8 months ago
1* Fork this val to your own profile.
2* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
3

switchbotmain.tsx3 matches

@stevekrouse•Updated 8 months ago
1// This val creates a simple web interface for opening the Val Town office door.
2// It uses the Hono framework for routing and HTML rendering, and interacts with
3// the SwitchBot API to control the door. The approach includes:
4// 1. A frontend route that displays a button to open the door
5// 2. A backend route that handles the door opening request
6// 3. Integration with SwitchBot API for door control
7// 4. Basic error handling and email notification on failure
8
29 .toString("base64");
30
31 const response = await fetch(`https://api.switch-bot.com/${path}`, {
32 headers: {
33 "Authorization": token,

switchbotmain.tsx3 matches

@stevekrouse•Updated 8 months ago
1// This val creates a simple web interface for opening the Val Town office door.
2// It uses the Hono framework for routing and HTML rendering, and interacts with
3// the SwitchBot API to control the door. The approach includes:
4// 1. A frontend route that displays a button to open the door
5// 2. A backend route that handles the door opening request
6// 3. Integration with SwitchBot API for door control
7// 4. Basic error handling and email notification on failure
8
29 .toString("base64");
30
31 const response = await fetch(`https://api.switch-bot.com/${path}`, {
32 headers: {
33 "Authorization": token,

whenfilmedmain.tsx8 matches

@tmcw•Updated 9 months ago
1// This val creates a movie guessing game using the TMDB API.
2// We'll fetch random movies from different years, present them to the user, and check their guesses.
3// Tradeoffs: We're using a free API with authentication for better data variety.
4
5import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo"
6import { blob } from "https://esm.town/v/std/blob"
7
8const TMDB_API_BASE = "https://api.themoviedb.org/3"
9const TMDB_IMAGE_BASE = "https://image.tmdb.org/t/p/w200"
10
11const headers = {
12 Authorization: `Bearer ${Deno.env.get("TMDB_API_KEY")}`,
13}
14
24 chosen.add(year)
25 const response = await fetch(
26 `${TMDB_API_BASE}/discover/movie?language=en-US&sort_by=popularity.desc&include_adult=false&include_video=false&page=1&primary_release_year=${year}`,
27 { headers },
28 )
80 <p><a href="/all-guesses">View All Guesses</a></p>
81 <div class="footer">
82 This product uses the TMDB API but is not endorsed or certified by TMDB.
83 <br>
84 <a href="https://www.themoviedb.org/" target="_blank">
141 <a href="/">Play Again</a> | <a href="/all-guesses">View All Guesses</a>
142 <div class="footer">
143 This product uses the TMDB API but is not endorsed or certified by TMDB.
144 <br>
145 <a href="https://www.themoviedb.org/" target="_blank">
187 <p><a href="/">Back to Quiz</a></p>
188 <div class="footer">
189 This product uses the TMDB API but is not endorsed or certified by TMDB.
190 <br>
191 <a href="https://www.themoviedb.org/" target="_blank">

emailmain.tsx2 matches

@std•Updated 9 months ago
1import { API_URL } from "https://esm.town/v/std/API_URL";
2import { parseSendGridEmail } from "https://esm.town/v/stevekrouse/parseSendGridEmail?v=8";
3import { parseSendGridEmails } from "https://esm.town/v/stevekrouse/parseSendGridEmails?v=10";
69}) => {
70 let result = await fetch(
71 `${API_URL}/v1/email`,
72 {
73 method: "POST",

daily-advice-app1 file match

@dcm31•Updated 12 hours ago
Random advice app using Advice Slip API

runValAPIEx2 file matches

@charmaine•Updated 1 day ago
rapilot330
YoungPapi