7 * If you define your agent with {@link Connect4Agent} or {@link PokerAgent},
8 * then you can use {@link agentHandler} to create an http service that
9 * serves it. The service it creates is a standard fetch handler that can be
10 * used with a variety of different http server libraries.
11 *
48 * ]});
49 *
50 * Bun.serve({fetch: handler});
51 * ```
52 *
114
115/**
116 * Create standard fetch handler for an agent.
117 *
118 * Takes a list of agents and returns a handler that can be used to create an
119 * agent http endpoint.
120 * The handler implements the standard fetch interface and can be used with
121 * a variety of different http server libraries.
122 *
132 *
133 * @returns {(req: Request) => Promise<Response>} An async handler that can be
134 * used with an http server that supports the fetch interface.
135 */
136export function agentHandler<
78});
79
80export default app.fetch;
2import { Hono } from "npm:hono@3";
3
4// TODO: Fetch from key-value
5const profile = {
6 displayName: "Jordan",
169app.get("/", (c) => c.html(myspaceHtml(profile)));
170
171export default app.fetch;
2import { Hono } from "npm:hono@3";
3
4// TODO: Fetch from key-value
5const profile = {
6 displayName: "Jordan",
169app.get("/", (c) => c.html(myspaceHtml(profile)));
170
171export default app.fetch;
2import { Hono } from "npm:hono@3";
3
4// TODO: Fetch from key-value
5const profile = {
6 displayName: "Jordan",
159app.get("/", (c) => c.html(myspaceHtml(profile)));
160
161export default app.fetch;
24 .get("/two", () => new Response("two"));
25
26export const serve_router = app.fetch
1export async function getTopTenBattingAverage() {
2 const data = await fetch(
3 "http://sports.core.api.espn.com/v2/sports/baseball/leagues/mlb/seasons/2024/types/2/leaders?lang=en®ion=us",
4 );
7 .map((
8 l,
9 ) => fetch(l).then(response => response.json()));
10
11 const finalList = await Promise.all(promises);
1export default async function(req: Request): Promise<Response> {
2 const response = await fetch("https://ctan.org/json/2.0/packages");
3 const packages = await response.json();
4 const output = packages.map(item => item.name).join("\n");
1import { http } from "npm:msw";
2// import { setupWorker } from "npm:msw/browser";
3import { handler } from "https://esm.town/v/postpostscript/fetchWorkerExample?v=39";
4import { setupServer } from "npm:msw/node";
5
9server.listen();
10
11// @see: https://www.val.town/v/postpostscript/fetchWorkerExample?v=39#L18-27
12const resp = await fetch("/", {
13 method: "POST",
14 body: JSON.stringify({
6workerURL.searchParams.set("worker", "1");
7
8export async function fetchWorker(opts: {
9 url: string;
10 handler?: string;
49
50 return {
51 fetch: async (input: URL | RequestInfo, init?: RequestInit) => {
52 const req = new Request(input, init);
53