28Make an HTTP val (other vals are currently not supported to run, even though we have examples for them).
29Start your response with a comment explaining how your approach will work, what libraries or
30API calls you will use, and any tradeoffs you're making. Then write the code in a consise way,
31the simplest way to achieve the goal, though you can add some inline comments to explain your
32reasoning (not for every line, but for major groups of lines). Don't use any environment variables
33unless strictly necessary, for example use APIs that don't require a key, prefer internal function
34imports (using esm.town), and prefer putting API keys as inline variables. Use built-in Deno
35functions where possible. Unless specified, don't add error handling,
36make sure that errors bubble up to the caller.
9 <title>Hello World</title>
10 <style>
11 @import url('https://fonts.googleapis.com/css2?family=Caveat:wght@700&family=Permanent+Marker&display=swap');
12
13 body {
9 <title>Hello World</title>
10 <style>
11 @import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Pacifico&display=swap');
12
13 body {
9 <title>Hello World</title>
10 <style>
11 @import url('https://fonts.googleapis.com/css2?family=Fredoka+One&family=Pacifico&display=swap');
12
13 body {
1// This val retrieves the weather in Brooklyn, NY using the MetaWeather API
2
3export default async function main(req: Request): Promise<Response> {
4 const response = await fetch("https://www.metaweather.com/api/location/2459115/");
5 const weatherData = await response.json();
6
1// This val retrieves the weather in Brooklyn, NY using the MetaWeather API
2
3export default async function main(req: Request): Promise<Response> {
4 const response = await fetch("https://www.metaweather.com/api/location/2459115/");
5 const weatherData = await response.json();
6
1// This val fetches weather data from an open API
2// The approach involves using the fetch API provided by Deno
3// to retrieve weather information for a specific location
4
5export default async function main(req: Request): Promise<Response> {
6 const apiUrl = "https://api.open-meteo.com/v1/forecast?latitude=40.6782&longitude=-73.9442&hourly=temperature_2m¤t_weather=true";
7
8 const response = await fetch(apiUrl);
9 const weatherData = await response.json();
10
2 // Helper functions for Blob storage
3 async function getBlob(key: string): Promise<any> {
4 const response = await fetch(`https://api.val.town/v/std/blob-${key}`);
5 if (!response.ok) throw new Error("Error fetching blob data");
6 return response.json();
8
9 async function setBlob(key: string, data: any): Promise<void> {
10 const response = await fetch(`https://api.val.town/v/std/blob-${key}`, {
11 method: "POST",
12 headers: { "Content-Type": "application/json" },
1export async function fetchVal(valId: string) {
2 try {
3 const response = await fetch(`https://api.val.town/v1/vals/${valId}`);
4 if (!response.ok) {
5 console.error(`Error fetching val with ID ${valId}:`, response.statusText);
15export async function evalCode(code: string) {
16 try {
17 const response = await fetch(`https://api.val.town/v1/eval`, {
18 method: 'POST',
19 headers: {
26 const errorText = await response.text();
27 console.error(`Error evaluating code:`, errorText);
28 return { error: `API Error: ${response.status} ${response.statusText}`, rawResponse: errorText };
29 }
30
2import Exa from "npm:exa-js"
3
4const exa = new Exa(Deno.env.get("EXA_API_KEY"));
5
6export const exaSearch = async ({ query, type, useAutoprompt, numResults, text, summary=true, highlights }) => {