Creating HTTP Servers
Bun's Bun.serve() API makes it incredibly easy to create fast HTTP servers. It's designed to be simple, fast, and production-ready.
Basic HTTP Server
Create a simple server with just a few lines:
Loading Bun Playground...
Handling Different Routes
Use the Request object to route requests:
Loading Bun Playground...
JSON Responses
Return JSON data easily:
Loading Bun Playground...
Request Methods
Handle different HTTP methods:
Loading Bun Playground...
Headers and CORS
Work with request and response headers:
Loading Bun Playground...
Exercise: Simple Router
Create a simple router function:
Loading Bun Exercise...
Exercise: API Response Builder
Create a reusable API response builder:
Loading Bun Exercise...

