Mercurial
comparison benchmark/bun-http-framework-benchmark/src/bun/bun-web-standard.ts @ 183:a8976a008a9d
[BenchMark] Added bun bench mark to test seoboe vs other popular benchmarks.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Fri, 23 Jan 2026 21:19:08 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 179:8d17f6e6e290 | 183:a8976a008a9d |
|---|---|
| 1 // Using Web Standard API to handle | |
| 2 // This is likely an real-world implementation | |
| 3 // if you're using pure Bun HTTP server | |
| 4 Bun.serve({ | |
| 5 port: 3000, | |
| 6 fetch: async (request) => { | |
| 7 const url = new URL(request.url) | |
| 8 | |
| 9 switch (request.method) { | |
| 10 case 'GET': | |
| 11 switch (url.pathname) { | |
| 12 case '/': | |
| 13 return new Response('Hi') | |
| 14 } | |
| 15 | |
| 16 if (url.pathname.startsWith('/id/')) { | |
| 17 const [id, rest] = url.pathname.slice(4).split('/') | |
| 18 | |
| 19 if (!rest) | |
| 20 return new Response( | |
| 21 `${id} ${url.searchParams.get('name')}`, | |
| 22 { | |
| 23 headers: { | |
| 24 'x-powered-by': 'benchmark' | |
| 25 } | |
| 26 } | |
| 27 ) | |
| 28 } | |
| 29 | |
| 30 return new Response('Not Found', { | |
| 31 status: 404 | |
| 32 }) | |
| 33 | |
| 34 case 'POST': | |
| 35 switch (url.pathname) { | |
| 36 case '/json': | |
| 37 return Response.json(await request.json()) | |
| 38 | |
| 39 default: | |
| 40 return new Response('Not Found', { | |
| 41 status: 404 | |
| 42 }) | |
| 43 } | |
| 44 | |
| 45 default: | |
| 46 return new Response('Not Found', { | |
| 47 status: 404 | |
| 48 }) | |
| 49 } | |
| 50 } | |
| 51 }) |