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.
rvorias avatar
turquoiseLlama
@rvorias
HTTP (deprecated)
An interactive, runnable TypeScript val by rvorias
janpaul123 avatar
semanticSearchTurso
@janpaul123
Script
Part of Val Town Semantic Search . Uses Turso to search embeddings of all vals, using the sqlite-vss extension. Call OpenAI to generate an embedding for the search query. Query the vss_vals_embeddings table in Turso using vss_search . The vss_vals_embeddings table has been generated by janpaul123/indexValsTurso . It is not run automatically. This table is incomplete due to a bug in Turso .
ytf avatar
updateTicketCoordinator
@ytf
Script
An interactive, runnable TypeScript val by ytf
zackoverflow avatar
minizod
@zackoverflow
Script
minizod Tiny Zod implementation. Why Zod is a dense library, and its module structure (or lack thereof) makes it difficult for bundlers to tree-shake unused modules . Additionally, using Zod in vals requires the await import syntax which means having to wrap every schema in a Promise and awaiting it. This is extremely annoying. So this is a lil-tiny-smol Zod meant for use in vals. A noteworthy use-case is using minizod to generate tyep-safe API calls to run vals outside of Val Town (such as client-side). Type-safe API call example We can use minizod to create type safe HTTP handlers and generate the corresponding code to call them using Val Town's API, all in a type-safe manner. First, create a schema for a function. The following example defines a schema for a function that takes a { name: string } parameter and returns a Promise<{ text: string }> . const minizodExampleSchema = () => @zackoverflow.minizod().chain((z) => z .func() .args(z.tuple().item(z.object({ name: z.string() }))) .ret(z.promise().return(z.object({ text: z.string() }))) ); With a function schema, you can then create an implementation and export it as a val: const minizodExample = @me.minizodExampleSchema().impl(async ( { name }, ) => ({ text: `Hello, ${name}!` })).json() In the above example, we call .impl() on a function schema and pass in a closure which implements the actual body of the function. Here, we simply return a greeting to the name passed in. We can call this val, and it will automatically parse and validate the args we give it: // Errors at compile time and runtime for us! const response = @me.minizodExample({ name: 420 }) Alternatively, we can use the .json() function to use it as a JSON HTTP handler: const minizodExample = @me.minizodExampleSchema().impl(async ( { name }, ) => ({ text: `Hello, ${name}!` })).json() // <-- this part We can now call minizodExample through Val Town's API. Since we defined a schema for it, we know exactly the types of its arguments and return, which means we can generate type-safe code to call the API: let generatedApiCode = @zackoverflow.minizodFunctionGenerateTypescript( // put your username here "zackoverflow", "minizodExample", // put your auth token here "my auth token", @me.minizodExampleSchema(), ); This generates the following the code: export const fetchMinizodExample = async ( ...args: [{ name: string }] ): Promise<Awaited<Promise<{ text: string }>>> => await fetch(`https://api.val.town/v1/run/zackoverflow.minizodExample`, { method: "POST", body: JSON.stringify({ args: [...args], }), headers: { Authorization: "Bearer ksafajslfkjal;kjf;laksjl;fajsdf", }, }).then((res) => res.json());
tmcw avatar
pdfExample
@tmcw
HTTP (deprecated)
Generate a pdf with pdf-lib 👉 Visit the web site generated by this Val pdf-lib is an incredible pure-JavaScript module that generates PDFs! In this example, it's generating a simple page that embeds the PDF, and exposes another route (with Hono ) that serves the PDF.
pomdtr avatar
ejm_test
@pomdtr
Script
An interactive, runnable TypeScript val by pomdtr
tmcw avatar
datascriptExample
@tmcw
Script
datascript example An example using tonsky’s datascript module, which implements a datalog-style database in JavaScript. The module itself is really written in ClojureScript, but they've helpfully produced an npm-compatible module for us to use. Datalog languages are fascinating, and have some real-world use in Roam Research and Logseq.
tmcw avatar
ittyRouterExample
@tmcw
HTTP (deprecated)
itty-router This is an example of using the Val Town Web API to integrate with itty-router . Server examples Hono Peko Itty Router Nhttp
vladimyr avatar
fetchTweet
@vladimyr
Script
Forked from dpetrouk/fetchTweet
jrmann100 avatar
pushSendNotification_negrel
@jrmann100
Script
Forked from jrmann100/pushSendNotification
crif avatar
pdfExample
@crif
HTTP (deprecated)
Forked from tmcw/pdfExample
tmcw avatar
parseEnglishExample
@tmcw
Script
nclst The nclst tree format is an extremely useful tree structure used for natural language processing. This is an example of parsing a string of English text into a syntax tree.
saolsen avatar
gltf_torus
@saolsen
HTTP (deprecated)
Builds a torus as a gltf file and displays it with https://modelviewer.dev/ based on https://www.donmccurdy.com/2023/08/01/generating-gltf/ https://github.com/mrdoob/three.js/tree/dev/src/geometries
iamseeley avatar
pinkBear
@iamseeley
Script
Forked from iamseeley/resumeConfig
kaleidawave avatar
ezno_checker_example
@kaleidawave
Script
Check a snippet using the Ezno type checker
pomdtr avatar
lowdb_example
@pomdtr
Script
Lowdb Example This val demonstrates the integration between valtown and lowdb . Read the Lodash section if you want to give superpowers to your DB.