Deno
This quickstart guide assumes you have Deno 1.x+ installed.
Steps
-
Create your
app.tsfile.app.tsimport { 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", }); }); }, }); -
Run your
app.tsfile.deno run --allow-net app.ts -
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