Bun provides a fast HTTP server viaDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/zhcndoc/bun/llms.txt
Use this file to discover all available pages before exploring further.
Bun.serve().
Powered by Mintlify
Auto-generate your docs
Build HTTP servers with Bun.serve()
Bun provides a fast HTTP server viaDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/zhcndoc/bun/llms.txt
Use this file to discover all available pages before exploring further.
Bun.serve().
Bun.serve({
port: 3000,
fetch(request) {
return new Response("Hello World");
},
});
Bun.serve({
port: 3000,
fetch(request) {
const url = new URL(request.url);
if (url.pathname === "/") {
return new Response("Home");
}
if (url.pathname === "/api/users") {
return Response.json({ users: [] });
}
return new Response("Not Found", { status: 404 });
},
});
Bun.serve({
async fetch(request) {
if (request.method === "POST") {
const data = await request.json();
return Response.json({ received: data });
}
return Response.json({ message: "Hello" });
},
});