- Home
- Skills
- Secondsky
- Claude Skills
- Bun Http Server
bun-http-server_skill
- TypeScript
52
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill secondsky/claude-skills --skill bun-http-server- SKILL.md5.7 KB
Overview
This skill provides practical guidance and ready patterns for building high-performance HTTP servers with Bun.serve in TypeScript. It covers request parsing, response types, simple routing, error handling, static file serving, CORS, TLS, and useful server options. Use it to quickly implement REST APIs, fetch handlers, and streaming responses with Bun.
How this skill works
The skill demonstrates creating a Bun server via Bun.serve and supplying a fetch(req) handler that inspects the incoming Request object. It shows parsing method, path, query parameters, headers, and the body via json(), formData(), text(), arrayBuffer(), or blob(). Responses include JSON, HTML, redirects, files, and ReadableStream-based streaming. Additional patterns cover routing, global error handling, server options (port, hostname, TLS, unix sockets), and static file serving.
When to use it
- Building lightweight REST APIs or microservices with Bun and TypeScript.
- Implementing request handlers for server-side rendering or API endpoints.
- Serving static assets from a public directory alongside an API.
- Creating streaming responses, server-sent events, or chunked outputs.
- Configuring HTTPS, custom ports, or unix socket bindings for production.
Best practices
- Read the request body only once; reuse parsed result rather than calling multiple body methods.
- Return Response.json(...) for JSON APIs and set explicit Content-Type for other payloads.
- Handle OPTIONS preflight and include CORS headers when exposing APIs to browsers.
- Use maxRequestBodySize to prevent large payload attacks and tune it per endpoint.
- Implement try/catch in fetch and an error(error) handler for global failures.
Example use cases
- A simple GET/POST REST API with dynamic route matching for /api/users/:id.
- Serving static files under /static/ from a public/ directory with existence checks.
- An HTTPS server using local TLS cert and key files for secure development or staging.
- A streaming endpoint that yields multiple chunks via ReadableStream for real-time feeds.
- A small proxy or middleware that inspects headers and forwards or modifies requests.
FAQ
Respond to OPTIONS preflight with appropriate Access-Control-Allow-* headers and attach the same headers to actual responses.
Why do I get 'Cannot read body' errors?
The body stream can be consumed only once. Parse it once (json/formData/text) and reuse the parsed value, or clone the request before consuming if needed.