Search
web_5If23gmesX
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function web_5If23gmesX(req) {
return new Response(`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vibrant Design Showcase</title>
<style>
body {
font-family: 'Arial', sans-serif;
run
@websandbox
An interactive, runnable TypeScript val by websandbox
Script
type SerializedRequest = {
headers: [string, string][];
method: string;
url: string;
body?: string;
type SerializedResponse = {
headers: [string, string][];
status: number;
statusText: string;
body: string;
decorator_router
@yieldray
Decorator Router Fair simple decorator based router, with GET/POST and middleware support. demo live demo: https://yieldray-decorator_router_demo.web.val.run/ import { get, post, all, use, registered, handler, type Context } from "https://esm.town/v/yieldray/decorator_router";
import { parseBearerAuth, transformResponse } from "https://esm.sh/serve-router@1.1.0/utils";
interface User {
id: number;
name: string;
}
const users: User[] = [
{ id: 0, name: "Alice" },
{ id: 1, name: "Ray" },
];
class _Server {
/**
* Decorator @get: Parses URLSearchParams into an object as the first parameter.
*/
@get("/users")
getAllUsers() {
return users; // Automatically wrapped in a Response.json
}
@get("/getUserByName") // GET /getUserByName?name=Alice
getUserByName({ name }: Record<string, string>) {
const user = users.find((u) => u.name === name);
if (user) {
return user; // Automatically wrapped as Response.json(user)
}
// Optionally, manually return a Response object
return Response.json({ error: "not found" }, { status: 404 });
}
@get("/user/:id") // GET /user/123
user(_: unknown, { params: { id } }: Context) {
return users.find((u) => u.id === Number(id));
}
/**
* Decorator @post: Parses the request body into an object as the first parameter.
*/
@post("/user") // POST /user
async createUser(user: User) {
if (users.find((u) => u.id === user.id)) {
return { error: "already exists!" };
}
await users.push(user); // Assume insertion into a database
return { ok: true, users };
}
@post("/user/:id") // POST /user/123
async updateUser(user: User, { params: { id }, request }: Context) {
const token = parseBearerAuth(request.headers.get("Authorization")!);
// Additional logic here...
}
@all("/")
home({ request }: { request: Request }) {
return {
registered,
method: request.method,
url: request.url,
headers: Object.fromEntries(request.headers.entries()),
};
}
@use("/*")
async corsMiddleware({ next, request }: Context) {
const resp = await next();
return transformResponse(resp, {
headers: {
"Access-Control-Allow-Origin": request.headers.get("origin") || "*",
},
});
}
}
// For Deno:
Deno.serve(handler);
// For val.town:
export default handler;
Script
# Decorator Router
Fair simple decorator based router, with GET/POST and middleware support.
## demo
live demo: <https://yieldray-decorator_router_demo.web.val.run/>
```ts
interface User {
export const app = ServeRouter({
onError(error) {
console.log(error);
const _registered: Array<{ method: string; path: string }> = [];
bbrun
@dglazkov
A simple chat app harness for your board Provides a very simple chat app UI for a Breadboard board. For now, requires you to be running a board server. This harness actually acts
as a proxy to the board server run API endpoint ,
and puts a nice (well, somewhat nice) frontend on top of it. The frontend is somewhat limited in what it can show, currently supporting only
LLMContent and array of LLMContent outputs, and only LLMContent array input. The script will look for the BB_LIVE_KEY in your Val Town environment, which
must contain your board server API key. To use, create an HTTP val, then import the proxy function from this script and call it like this:
import { proxy } from "https://esm.town/v/dglazkov/bbrun";
export default proxy(
"url-to-the-board.bgl.json",
);
Script
# A simple chat app harness for your board
Provides a very simple chat app UI for a [Breadboard](https://breadboard-ai.web.app/) board.
For now, requires you to be running a board server. This harness actually acts
as a proxy to the board server [run API endpoint](https://breadboard-ai.github.io/breadboard/docs/reference/board-run-api-endpoint/),
and puts a nice (well, somewhat nice) frontend on top of it.
The frontend is somewhat limited in what it can show, currently supporting only
const DEFAULT_FRONTEND_MODULE = "https://esm.town/v/dglazkov/bbrunfe";
* You can supply these options as a second argument to the `proxy` function.
* These options are used to configure the frontend.
export type FrontendOptions = {
projects
@willthereader
@jsxImportSource https://esm.sh/hono@latest/jsx
HTTP
/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
export const projects = (c: Context) => {
return c.html(
<html>
<head>
<title>Projects</title>
<style
dangerouslySetInnerHTML={{
__html:
`:root{--slate1: hsl(200, 7%, 8.8%);--slate2: hsl(195, 7.1%, 11%);--slate3: hsl(197, 6.8%, 13.6%);--slate4: hsl(198, 6.6%, 15.8%);--slate5: hsl(199, 6.4%, 17.9%);--slate6: hsl(201, 6.2%, 20.5%);--slate7: hsl(203, 6%, 24.3%);--slate8: hsl(207, 5.6%, 31.6%);--slate9: hsl(206, 6%, 43.9%);--slate10: hsl(206, 5.2%, 49.5%);--slate11: hsl(206, 6%, 63%);--slate12: hsl(210, 6%, 93%);--blue1: hsl(212, 35%, 9.2%);--blue2: hsl(216, 50%, 11.8%);--blue3: hsl(214, 59.4%, 15.3%);--blue4: hsl(214, 65.8%, 17.9%);--blue5: hsl(213, 71.2%, 20.2%);--blue6: hsl(212, 77.4%, 23.1%);--blue7: hsl(211, 85.1%, 27.4%);--blue8: hsl(211, 89.7%, 34.1%);--blue9: hsl(206, 100%, 50%);--blue10: hsl(209, 100%, 60.6%);--blue11: hsl(210, 100%, 66.1%);--blue12: hsl(206, 98%, 95.8%)}body{font-family:system-ui,sans-serif;margin:auto;padding:20px;max-width:65ch;text-align:left;word-wrap:break-word;overflow-wrap:break-word;line-height:1.5}h1,h2,h3,h4,h5,h6,strong,b{font-weight:500}a{color:var(--blue10)}nav a{margin-right:10px}textarea{width:100%;font-size:16px}input{font-size:16px}content{line-height:1.6}table{width:100%}img{max-width:100%;height:auto}code{padding:2px 5px;background-color:var(--slate4);font-family:menlo,monospace}pre{padding:1rem}pre>code{all:unset}blockquote{border:1px solid var(--slate10);color:var(--slate11);padding:2px 0 2px 20px;margin:0;font-style:italic}a[data-astro-cid-eimmu3lg]{display:inline-block;text-decoration:none}a[data-astro-cid-eimmu3lg].active{font-weight:600;text-decoration:underline}header[data-astro-cid-3ef6ksr2]{margin:0 0 2em}h2[data-astro-cid-3ef6ksr2]{margin:.5em 0}`,
site
@nikita
An interactive, runnable TypeScript val by nikita
Script
export let site = (req, res) => {
if (req.method === "get") {
res.type("html").send(/* html */ `
<html>
<h1>Welcome</h1>
<form action="https://api.val.town/express/@nikita.site" method="post">
<label>Email
<input type="text" name="email"/>
</label>
<button type="submit">Submit</submit>
hi
@just_be
An interactive, runnable TypeScript val by just_be
HTTP
export default async function server(req: Request): Promise<Response> {
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello world</title>
<style>
body {
blackRodent
@stevekrouse
@jsxImportSource https://esm.sh/hono@latest/jsx
HTTP
/** @jsxImportSource https://esm.sh/hono@latest/jsx **/
export const projects = (c: Context) => {
return c.html(
<html>
<head>
<title>Projects</title>
<style
dangerouslySetInnerHTML={{
__html:
`:root{--slate1: hsl(200, 7%, 8.8%);--slate2: hsl(195, 7.1%, 11%);--slate3: hsl(197, 6.8%, 13.6%);--slate4: hsl(198, 6.6%, 15.8%);--slate5: hsl(199, 6.4%, 17.9%);--slate6: hsl(201, 6.2%, 20.5%);--slate7: hsl(203, 6%, 24.3%);--slate8: hsl(207, 5.6%, 31.6%);--slate9: hsl(206, 6%, 43.9%);--slate10: hsl(206, 5.2%, 49.5%);--slate11: hsl(206, 6%, 63%);--slate12: hsl(210, 6%, 93%);--blue1: hsl(212, 35%, 9.2%);--blue2: hsl(216, 50%, 11.8%);--blue3: hsl(214, 59.4%, 15.3%);--blue4: hsl(214, 65.8%, 17.9%);--blue5: hsl(213, 71.2%, 20.2%);--blue6: hsl(212, 77.4%, 23.1%);--blue7: hsl(211, 85.1%, 27.4%);--blue8: hsl(211, 89.7%, 34.1%);--blue9: hsl(206, 100%, 50%);--blue10: hsl(209, 100%, 60.6%);--blue11: hsl(210, 100%, 66.1%);--blue12: hsl(206, 98%, 95.8%)}body{font-family:system-ui,sans-serif;margin:auto;padding:20px;max-width:65ch;text-align:left;word-wrap:break-word;overflow-wrap:break-word;line-height:1.5}h1,h2,h3,h4,h5,h6,strong,b{font-weight:500}a{color:var(--blue10)}nav a{margin-right:10px}textarea{width:100%;font-size:16px}input{font-size:16px}content{line-height:1.6}table{width:100%}img{max-width:100%;height:auto}code{padding:2px 5px;background-color:var(--slate4);font-family:menlo,monospace}pre{padding:1rem}pre>code{all:unset}blockquote{border:1px solid var(--slate10);color:var(--slate11);padding:2px 0 2px 20px;margin:0;font-style:italic}a[data-astro-cid-eimmu3lg]{display:inline-block;text-decoration:none}a[data-astro-cid-eimmu3lg].active{font-weight:600;text-decoration:underline}header[data-astro-cid-3ef6ksr2]{margin:0 0 2em}h2[data-astro-cid-3ef6ksr2]{margin:.5em 0}`,
dynamicFormInput
@yawnxyz
An interactive, runnable TypeScript val by yawnxyz
HTTP
/** @jsx jsx */
const app = new Hono();
const Layout = ({ children, title = "Dynamic Form Example" }) => (
<html lang="en">
<head>
<title>{title}</title>
<script src="https://unpkg.com/htmx.org@1.9.9"></script>
</head>
<body>
{children}
scarletSole
@tempdev
An interactive, runnable TypeScript val by tempdev
HTTP
interface Context {
url: string;
const app = new Hono();
app.get("/dood/:dood", async (c) => {
const { dood } = c.req.param();
const ctx = { url: "https://d000d.com/e/" + dood };
return c.json(await doodstream(ctx));
app.get("/tape/:tape", async (c) => {
const { tape } = c.req.param();
const ctx = { url: "https://streamtape.com/e/" + tape };
scarletSole
@tempguy
An interactive, runnable TypeScript val by tempguy
HTTP
interface Context {
url: string;
const app = new Hono();
app.get("/dood/:dood", async (c) => {
const { dood } = c.req.param();
const ctx = { url: "https://d000d.com/e/" + dood };
return c.json(await doodstream(ctx));
app.get("/tape/:tape", async (c) => {
const { tape } = c.req.param();
const ctx = { url: "https://streamtape.com/e/" + tape };
searchmessages
@tfayyaz
@jsxImportSource npm:hono/jsx
HTTP
/** @jsxImportSource npm:hono/jsx **/
// import val sqlite
const app = new Hono();
const title = "Click Button Demo";
const View = ({ rows }) => {
// create search form
// create html table from all rows
return (
<html>
<head>
valleBlogV0
@janpaul123
Fork this val to your own profile. Create a Val Town API token , open the browser preview of this val, and use the API token as the password to log in.
HTTP
* Fork this val to your own profile.
* Create a [Val Town API token](https://www.val.town/settings/api), open the browser preview of this val, and use the API token as the password to log in.
async function main(req: Request): Promise<Response> {
const { readable, writable } = new TransformStream();
const writer = writable.getWriter();
const write = (text) => writer.write(new TextEncoder().encode(text));
(async () => {
write(`<!DOCTYPE html>
<html>
<head><link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" /></head>
html
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export let html = (content, options = {}) =>
new Response(content, {
headers: {
"Content-Type": "text/html",
...(options.headers ?? {}),
monacoEditor
@yawnxyz
An interactive, runnable TypeScript val by yawnxyz
HTTP
const app = new Hono();
app.get('/', (c) => {
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Monaco Editor with Hono</title>
<style>