Search

Results include substring matches and semantically similar vals. Learn more
pomdtr avatar
prolificVioletToucan
@pomdtr
An interactive, runnable TypeScript val by pomdtr
HTTP
export default async function (req: Request): Promise<Response> {
return Response.json({ ok: true })
antonnyman avatar
honoExample
@antonnyman
Hono Here's an example using the Hono server library with the Web API . It works great! Server examples Hono Peko Itty Router Nhttp
HTTP
# Hono
Here's an example using the [Hono](https://hono.dev/) server library with the [Web API](https://docs.val.town/api/web). It wo
### Server examples
- [Hono](https://www.val.town/v/tmcw.honoExample)
- [Peko](https://www.val.town/v/tmcw.pekoExample)
- [Itty Router](https://www.val.town/v/tmcw.ittyRouterExample)
export const honoExample = async (req: Request) => {
const { Hono } = await import("npm:hono@3");
const app = new Hono();
app.get("/", (c) => c.text("Hono?"));
alp avatar
proxyFetch8
@alp
An interactive, runnable TypeScript val by alp
Script
import { fetch } from "https://esm.town/v/std/fetch";
export const proxyFetch8 = async (req, res) => {
const { url, options } = req.body;
try {
const response = await fetch(url, options);
return res.status(response.status).send(await response.text());
} catch (e) {
const errorMessage = e instanceof Error ? e.message : "Unknown error";
console.error("Failed to initiate fetch", e);
return res.status(500).send(`Failed to initiate fetch: ${errorMessage}`);
stevekrouse avatar
valOutput
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export async function valOutput(req: Request) {
const url = new URL(req.url);
const pattern = /^\/([^\/]+)\/([^@]+)(?:@([^\.]+))?$/;
const match = url.pathname.match(pattern);
if (!match) {
return new Response("invalid request", { status: 400 });
const author = match[1];
const name = match[2];
const val = await fetchJSON(
`https://api.val.town/v1/alias/${author}/${name}`,
tmcw avatar
elysiaExample
@tmcw
Elysia example This is how you can use Elysia with Val Town.
HTTP
# Elysia example
This is how you can use [Elysia](https://elysiajs.com) with Val Town.
export const elysiaExample = async (req) => {
const { Elysia } = await import("https://esm.sh/elysia@0.7.15");
const app = new Elysia()
.get("/", () => "Hello Elysia");
return app.fetch(req);
dhvanil avatar
val_jATkKH8yPO
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export const jsonOkExample = () => Response.json({ ok: true });
curtcox avatar
_not_actually_private_so_that_you_can_see_it
@curtcox
This is public so you can see what's in it. If it had real secrets, it should be private. See https://www.val.town/v/curtcox/reply_to_slack_message
HTTP
This is public so you can see what's in it. If it had real secrets, it should be private.
See https://www.val.town/v/curtcox/reply_to_slack_message
import { reply_to_slack_message, SlackConfig } from "https://esm.town/v/curtcox/reply_to_slack_message";
// This is for informational purposes only.
// It needs real tokens to work.
export const chatio = (req: Request) => {
const config: SlackConfig = {
slackToken: "See Val Town docs for how to get this token",
slackVerificationToken: "See Val Town docs for how to get this token",
return reply_to_slack_message(req, processor, config);
byjonathanleung avatar
setZ
@byjonathanleung
An interactive, runnable TypeScript val by byjonathanleung
Script
let { Z } = await import("https://esm.town/v/byjonathanleung/Z");
export const setZ = (newValue) => {
Z = newValue;
return Z
dhvanil avatar
web_kH7d5ah6xz
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function web_kH7d5ah6xz(req) {
return new Response(`<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The Dark Hours: Global Patterns Reveal AI's Secret Evolution</title>
<style>
body {
background-color: #000;
joseforonda avatar
noticiasfides
@joseforonda
An interactive, runnable TypeScript val by joseforonda
Cron
let { parse } = await import("npm:node-html-parser");
const fetchPage = async (page: number) => {
const url = `https://www.noticiasfides.com/paginas/buscador?nc=.&page=${page}`;
const response = await fetch(url, { signal: AbortSignal.timeout(10000) });
const text = await response.text();
const html = parse(text);
return html;
const parseEntry = (entry: any) => {
const parseDate = (date: string) => {
const months = {
dhvanil avatar
val_iWH7hGnj6J
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_iWH7hGnj6J(req) {
try {
// Execute the code directly and capture its result
const result = await (async () => {
const isPalindrome = (str) => {
const reversed = str.split('').reverse().join('');
return str === reversed;
const findPalindromicSubstrings = (str) => {
const palindromes = [];
for (let i = 0; i < str.length; i++) {
andreterron2 avatar
_
@andreterron2
An interactive, runnable TypeScript val by andreterron2
Script
export const _ = import("npm:lodash");
whatrocks avatar
foo
@whatrocks
// email yourself as easily as logging to the console
Script
// email yourself as easily as logging to the console
export async function foo() {
const username = "whatrocks";
const today = new Date().toDateString();
console.log("today: ", today);
const url = `https://searchcaster.xyz/api/search?text=%E2%8C%86&username=${username}`;
let old_fling = "";
const response = await fetch(url);
const jsonData = await response.json();
console.log(jsonData);
stevekrouse avatar
tealBadger
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
HTTP
export default async function(req: Request): Promise<Response> {
const openai = new OpenAI();
const stream = await openai.chat.completions.create({
stream: true,
messages: [{ role: "user", content: "Write a poem in the style of beowulf about the DMV" }],
model: "gpt-3.5-turbo",
max_tokens: 2048,
return new Response(
new ReadableStream({
async start(controller) {
dhvanil avatar
val_1jzxJ5oCHe
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export const jsonOkExample = () => Response.json({ ok: true });