Skip to Content
Drash v3 is in beta. APIs may change.

Bun

Use the polyfill entry point. Bun exposes Web Request/Response, but not a URLPattern that Drash can rely on across versions.

Install

bun install @drashland/drash

App

import { Application, Resource, } from "@drashland/drash/modules/http.polyfill.js"; class Home extends Resource { paths = ["/"]; GET(request: Request) { return new Response("Oh so easy"); } } const app = Application .builder() .resources(Home) .build(); Bun.serve({ hostname: "localhost", port: 1447, fetch(request: Request): Promise<Response> { return app .handle<Response>(request) .catch(() => { return new Response("Sorry, but we hit an error!", { status: 500, statusText: "Internal Server Error", }); }); }, });

Run

bun run app.ts

Then visit http://localhost:1447.

Notes

Apart from the entry point and the server call, this is identical to the Deno guide — both pass a Web Request straight through and return a Web Response.

A runnable version lives in examples/bun-ts.

Last updated on