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

Deno

This quickstart guide assumes you have Deno 1.x+ installed.

Steps

  1. Create your app.ts file.

    app.ts
    import { Application, Resource, } from "npm:@drashland/drash/modules/http.native.js"; class Home extends Resource { paths = ["/"]; GET(request: Request) { return new Response(`Oh so easy`); } } const app = Application .builder() .resources(Home) .build(); Deno.serve({ hostname: "localhost", port: 1447, handler: (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", }); }); }, });
  2. Run your app.ts file.

    deno run --allow-net app.ts
  3. Visit http://localhost:1447  to verify your app is running.

Notes

Deno’s native Request is passed straight through, so your resource methods receive a real Request.

Deno expects a native Response, so your resources should return a real Response.

app.handle() returns a promise that rejects on error — including HTTPError. Nothing is written to the socket for you, so the .catch() block is where you decide what the client sees. See HTTPError to learn more about handling and returning error responses.

Last updated on