Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

generate UUID v4 every 200ms in streaming response.

Note that streaming is not available in Val Town as of May 2024.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
export default async function fetch(req: Request) {
const countParam = new URL(req.url).searchParams.get("count");
if (countParam === null) {
return new Response("Missing count parameter", { status: 400 });
}
const count = Math.min(+countParam, 100);
if (!Number.isFinite(count)) {
return new Response("Invalid count parameter", { status: 400 });
}
const body = new ReadableStream({
async start(controller) {
for (const _ of Array(count)) {
controller.enqueue(`${crypto.randomUUID()}\n`);
await new Promise((resolve) => setTimeout(resolve, 200));
}
controller.close();
},
}).pipeThrough(new TextEncoderStream());
return new Response(body, {
headers: {
"Content-Type": "text/plain",
"Transfer-Encoding": "chunked",
},
});
}
reosablo-uuidgeneratorstream.web.val.run
May 4, 2024