Back to APIs list
Github API examples & templates
Use these vals as a playground to view and fork Github API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
earthquakes
@fil
HTTP
Earthquake map 🌏 This val loads earthquake data from USGS, a topojson file for the land shape, and supporting libraries. It then creates a map and save it as a SVG string. The result is cached for a day. Note that we must strive to keep it under val.town’s limit of 100kB, hence the heavy simplification of the land shape. (For a simpler example, see becker barley .) | | |
|-----|-----|
| Web page | https://fil-earthquakes.web.val.run/ |
| Observable Plot | https://observablehq.com/plot/ |
| linkedom | https://github.com/WebReflection/linkedom |
| topojson | https://github.com/topojson/topojson |
| earthquakes | https://earthquake.usgs.gov |
| world | https://observablehq.com/@visionscarto/world-atlas-topojson |
| css | https://milligram.io/ |
tinygoHttpExample
@maxm
HTTP (deprecated)
A Go http handler running in Val Town: The Go source is here . Mandelbrot rendering code taken from here . I used maxm/compileAndUploadTinygoWasm to compile the code and create the val. $ git clone git@github.com:maxmcd/go-town.git
$ cd go-town/val-town-tinygo-http-example
$ deno run --allow-net --allow-run --allow-read "https://esm.town/v/maxm/compileAndUploadTinygoWasm?v=58"
Running tinygo build -o main.wasm -target=wasi .
Compliation complete
Running wasm-strip main.wasm
Copy the following into a val town HTTP val:
import { wasmHandler } from "https://esm.town/v/maxm/tinygoHttp";
const resp = await fetch("https://maxm-wasmblobhost.web.val.run/jpxqvyy5tphiwehzklmioklpkpz4gpzs.wasm");
const handler = await wasmHandler(new Uint8Array(await resp.arrayBuffer()));
export default async function(req: Request): Promise<Response> {
return handler(req);
}
compileAndUploadTinygoWasm
@maxm
Script
Compile and Upload Tinygo WASM to Val Town Using Deno Make a Go program like so: package main
import (
"fmt"
"net/http"
gotown "github.com/maxmcd/go-town"
)
func main() {
gotown.ListenAndServe(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
}))
} Make sure you have tinygo (and optionally wasm-strip) installed. Then run this command with Deno to invoke this script: deno run --allow-net --allow-run --allow-read \
"https://esm.town/v/maxm/compileAndUploadTinygoWasm?v=58" That will print out the following: Running tinygo build -o main.wasm -target=wasi .
Compliation complete
Running wasm-strip main.wasm
Copy the following into a val town HTTP val:
import { wasmHandler } from "https://esm.town/v/maxm/tinygoHttp";
const resp = await fetch("https://maxm-wasmBlobHost.web.val.run/jpxqvyy5tphiwehzklmioklpkpz4gpzs.wasm");
const handler = await wasmHandler(new Uint8Array(await resp.arrayBuffer()));
export default async function(req: Request): Promise<Response> {
return handler(req);
} Copy that into a Val and you have a working Go http handler! View that example here: https://www.val.town/v/maxm/crimsonMacaw
minifyHTML
@yieldray
Script
Usage: import { minifyHTML } from "https://esm.town/v/yieldray/minifyHTML";
const minified = await minifyHTML("<html>...</html>", { ...options }); As an API: import { runVal } from "https://esm.town/v/std/runVal";
const minified = awaitrunVal("yieldray.minifyHTML", "<html>...</html>", { ...options });