45[LastLogin](https://lastlogin.io/) is a decentralized hosted auth provider
6that enables login to any app through email, Google, Github, etc without API keys.
78This val exports middleware that can be added to any HTTP val.
23export let currency = async (desired, base = "usd", amount = 1) => {
4let { rates } = await fetchJSON(`https://open.er-api.com/v6/latest/${base}`);
5if (rates && rates[desired.toUpperCase()]) return amount * (rates[desired.toUpperCase()]);
6else {
7let { rates } = await fetchJSON(
8`https://api.coingecko.com/api/v3/exchange_rates?&x_cg_demo_api_key=${Deno.env.get("COINGECKO_API_KEY")}`,
9);
10return amount * rates[desired.toLowerCase()]?.value / rates[base.toLowerCase()]?.value;
211Make an HTTP val (other vals are currently not supported to run, even though we have examples for them).
212Start your response with a comment explaining how your approach will work, what libraries or
213API calls you will use, and any tradeoffs you're making. Then write the code in a consise way,
214the simplest way to achieve the goal, though you can add some inline comments to explain your
215reasoning (not for every line, but for major groups of lines). Don't use any environment variables
216unless strictly necessary, for example use APIs that don't require a key, prefer internal function
217imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
218functions where possible. Unless specified, don't add error handling,
219make sure that errors bubble up to the caller.
220Avoid external images or base64 images, use emojis, unicode symtols, or icon fonts/libraries instead, unless that's
221not practical for the user's request (e.g. if they ask for a particular animated gif).
222If the user asks for something that requires persistence, use the Val Town Blob storage API, unless
223explicitly specified otherwise. Use the current val name for the storage key, which you can get
224using 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
393We 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
12041205const tempValName = `valle_tmp_${Math.random() * 10}`.replaceAll(".", "");
1206// Errors in running the val bubble up through this API, so ignore them.
1207await vt.vals.create({ name: tempValName, code: newCode, type: "http" as any, privacy: "unlisted" }).catch(
1208(error) => {
1import { fetch } from "https://esm.town/v/std/fetch";
2import { resyPublicAPIKey } from "https://esm.town/v/vtdocs/resyPublicAPIKey";
34export const resyAuth = async (email: string, password: string): Promise<{
9}[];
10}> => {
11const 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
13const readmeVals: any = await (await fetch("https://janpaul123-readmevals.web.val.run/")).json();
1415const API_URL = "https://api.val.town";
1617const sections = [
129{
130prompt: "Write a val that accesses environment variables",
131code: `const res = await fetch("${API_URL}/v1/me", {
132headers: {
133Authorization: \`Bearer \${Deno.env.get("valtown")}\`,
141code: `import process from "node:process";
142
143const res = await fetch("${API_URL}/v1/me", {
144headers: {
145Authorization: \`Bearer \${process.env.valtown}\`,
310You can attach files to your emails by using the \`attachments\` field.
311Attachments need to be [Base64](https://en.wikipedia.org/wiki/Base64) encoded,
312which is that the [btoa](https://developer.mozilla.org/en-US/docs/Web/API/btoa)
313method is doing in this example:
314
412\`\`\`
413
414### Lower-level API
415
416We 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
458role: "assistant",
459content:
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¤t_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
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
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
829.toString("base64");
3031const response = await fetch(`https://api.switch-bot.com/${path}`, {
32headers: {
33"Authorization": token,
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
829.toString("base64");
3031const response = await fetch(`https://api.switch-bot.com/${path}`, {
32headers: {
33"Authorization": token,
whenfilmedmain.tsx8 matches
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.
45import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo"
6import { blob } from "https://esm.town/v/std/blob"
78const TMDB_API_BASE = "https://api.themoviedb.org/3"
9const TMDB_IMAGE_BASE = "https://image.tmdb.org/t/p/w200"
1011const headers = {
12Authorization: `Bearer ${Deno.env.get("TMDB_API_KEY")}`,
13}
1424chosen.add(year)
25const 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">
82This 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">
143This 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">
189This product uses the TMDB API but is not endorsed or certified by TMDB.
190<br>
191<a href="https://www.themoviedb.org/" target="_blank">
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}) => {
70let result = await fetch(
71`${API_URL}/v1/email`,
72{
73method: "POST",