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.
jeffreyyoung avatar
poe_bot
@jeffreyyoung
Script
// copied from https://github.com/poe-platform/fastapi_poe/blob/72e0ffdd00553d24ef23755138ca9b8d5f08b201/src/fastapi_poe/types.py
tmcw avatar
punycodeExample
@tmcw
Script
punycode punycode is so cool. It's esoteric, but like, it's amazing what ingenuity can do. It's an encoding of UTF-8 - the kind of text with easy representations for unicode sequences like ñ - in ASCII - the one that just supports English. It does this in a way that's reversible, and lets us use UTF8 text in ASCII places, because you can also detect when something is written in punycode. Do you need this, probably not – but someday you will, and you will remember.
ajn avatar
dailyDadJoke
@ajn
Cron
Forked from stevekrouse/dailyDadJoke
tmcw avatar
hastscriptExample
@tmcw
Script
hastscript hastscript is a way to create 'HTML trees' - then you can translate that tree into HTML using hast-util-to-html . It's pretty neat and straightforward to use in Val Town because it supports ESM exports.
petermillspaugh avatar
emailSubscription
@petermillspaugh
HTTP (deprecated)
Val Town email subscriptions 📧 Handles email subscription signup+verification and sending. Steps Fork and run the sibling Vals to set up SQLite tables: createSubscribers , createNewsletters , createEmailLogs Fork this Val and update for your use case (e.g. confirmation link, sendEmail args, form fields, etc.) Add an HTML form to your frontend that calls /send-verification , or just use / to return a simple HTML form Add a confirmation page on the frontend that calls /confirm-verification Fork sibling Vals to get verification email markup , send verification emails , create a list of newsletters , create a newsletter template , create an individual newsletter , send test emails , send emails , and handle unsubscribe Optionally, fork cousin Vals to view subscribers , email yourself daily subscriber count , email yourself a reminder to write your next newsletter , and send test emails Frontend form You should have a form that hits the /send-verification API endpoint on submit. Remember to adjust the endpoint URL to that of your fork (or else you'll be signing people up for my website!). As a simple alternative, you could use the / handler of this Val, which returns a simple HTML form. Here's a simple example using React: const EmailSignupForm = () => { const [name, setName] = useState(""); const [email, setEmail] = useState(""); async function handleSubmit(e) { e.preventDefault(); setName(""); setEmail(""); const formData = new FormData(); formData.append("name", name); formData.append("email", email); await fetch("https://petermillspaugh-emailSubscription.web.val.run/send-verification", { method: "POST", body: formData, }); } return ( <form onSubmit={handleSubmit}> <label htmlFor="name">First name</label> <input id="name" value={name} onChange={(e) => setName(e.target.value)} type="text" required={true} /> <label htmlFor="email">Email</label> <input id="email" value={email} onChange={(e) => setEmail(e.target.value)} type="email" required={true} /> <button type="submit">Subscribe</button> </form> ); }; You can see a full example on petemillspaugh.com: signup in the footer and code on github . You can add/remove input fields as you wish, of course (e.g. maybe you don't need a name, or maybe you want a how'd-you-hear-about-us field). Just adjust the SQL and frontend implementation accordingly. Frontend confirmation page Create a confirmation page that accepts an email and token as query params and calls the /confirm-verification endpoint. Simple example using React (and Next.js /page directory): const EmailConfirmationPage = () => { const router = useRouter(); const { email, token } = router.query; const [isConfirmed, setIsConfirmed] = useState(false); useEffect(() => { async function confirmEmail() { if (!email || !token) return; const response = await fetch(`https://petermillspaugh-emailSubscription.web.val.run/confirm-verification?email=${email}&token=${token}`, { method: "PUT", }); const { confirmed } = await response.json(); if (confirmed) setIsConfirmed(true); } confirmEmail(); }, [email, token]); if (!isConfirmed) return null; return ( <main> <h1>You’re all set!</h1> </main> ); }; Full example is here and code is here . As an alternative, you could make /confirm-verification a GET route and have your email confirmation link sent by the first route be https://petermillspaugh-emailSubscription.web.val.run/confirm-verification?email=${email}&token=${token} (swapping in your namespace). That would be marginally faster, probably, but you'd still need some way to convey confirmation to the user (e.g. add some "You're all set" message to the return). Plus, the route writes to the subscribers table, so a PUT feels more appropriate. Notes Sending emails to people other than yourself on Val Town is a paid feature—if you want to stay on the free plan, you can go with a package like nodemailer or @sendgrid/mail
stevekrouse avatar
axiosEx
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
pattysi avatar
OpenAI
@pattysi
Script
Forked from std/openai
nbbaier avatar
mirroredSearchAPI
@nbbaier
HTTP (deprecated)
Expanded search endpoint This is a mirrored version of the Val Town API /search/vals endpoint, meant mostly for use with pomdtr's vscode extension . It allows for more sophisticated filtering of the results of a search.
std avatar
turso
@std
Script
Deprecated in favor of std/sqlite (also powered by Turso) std/turso was the initial version of our integration with Turso. It was so popular, we rebuilt it to be faster and easier to use: std/sqlite . Turso is a serverless SQLite platform designed for the edge. It runs libSQL , their open contribution fork of SQLite. Every Val Town user automatically gets their own Turso SQLite database! It's great for >100kb data (ie bigger than a val) or when you need SQL: relations, ACID transactions, etc. Storage used in Turso will count against your Val Town total storage (10mb for free users; 1gb for Pro users). Contact us if you'd need more – it should be no problem! Getting started This val uses our public key auth scheme . Generate your keypair On your publicKey click the lock icon🔒 to change the permissions to Unlisted . Fork this helper function replacing stevekrouse with your own username Try out some queries! Usage This val returns a Turso SDK's Client , which supports execute , batch , and transaction . await @me.turso().execute(`create table blobs( key text unique, value text )`) More example usage Architecture This @std.turso function is the client or SDK to @std.tursoAPI, which acts as a "proxy" to Turso. It handles authentication, creates databases, and forwards on your SQL queries. You can get lower latency (~200ms vs ~800ms), more storage, databases, CLI & API access by having your own Turso account.
curtcox avatar
MarkdownCommand
@curtcox
Script
An interactive, runnable TypeScript val by curtcox
dthyresson avatar
graphQLYogaDeferAndStream
@dthyresson
HTTP
Forked from dthyresson/graphQLYoga
pomdtr avatar
browser
@pomdtr
Script
Types for the val.town web extension
nbbaier avatar
PGlite
@nbbaier
HTTP (deprecated)
Forked from samwillis/PGliteOld
karfau avatar
chai
@karfau
Script
// @deno-types="https://unpkg.com/@types/chai/index.d.ts"
yawnxyz avatar
translate
@yawnxyz
HTTP (deprecated)
Forked from yieldray/translate
wangqiao1234 avatar
OpenAI
@wangqiao1234
Script
Forked from std/openai