GitHub release Travis (.org) branch deno version deno_std version

Drash

Drash is a microframework for Deno based on HTTP resources and content negotiation.

Drash is designed to help you build your project(s) quickly with the ability to scale. You can build an API, a SaaS, a web app, an SPA (like the documentation pages), or even a static HTML site. How you use Drash is up to you, so that it can be everything you need and nothing you don’t.

Features

HTTP Resources

Drash uses HTTP resources. It doesn’t use controllers and it doesn’t use app.get('/', someHandler())-like syntax. You create a resource class, define its URIs, and give it HTTP methods (e.g., GET(), POST(), PUT(), DELETE(), etc.).

Static Paths

Drash servers can handle requests for static assets like CSS files, JS files, and more. Depending on your use case (like building a web app with your own custom stylesheets and scripts), you might want to serve static assets. To do this, just include your list of static paths in the Drash server’s static_paths config.

Request Path Params (e.g., /users/:id)

Resources can access their URI’s path params via this.request.path_params.some_param–allowing you to build RESTful/ish APIs.

Request URL Query Params (e.g., /users?id=1234)

Resources can access the request’s URL query params via this.request.url_query_params.some_param.

Request Body (e.g., {"id":"1234"})

Resources can access the request’s body via this.request.body_parsed.some_param. Supported content types are application/json and application/x-www-form-urlencoded.

Semantic Method Names

If you want your resource class to allow GET requests, then give it a GET() method. If you want your resource class to allow POST requests, then give it a POST() method. If you don’t want your resource class to allow DELETE requests, then don’t give your resource class a DELETE() method. Pretty simple ideology and very semantic.

Content Negotiation

Drash is based on resources and you can’t have true resources unless clients can request different representations of those resources through content negotiation. Out of the box, Drash’s Drash.Http.Response class can generate the following representations for resources: application/json, text/html, application/xml, and text/xml. Getting the Drash.Http.Response class to handle more representations is easy. Read the Adding Content Types tutorial for more information.

Install

// Import Drash latest release
import Drash from "https://deno.land/x/drash@v0.8.3/mod.ts";

// Import Drash master
import Drash from "https://deno.land/x/drash/mod.ts";

It is recommended that you import the latest release or a specific release to prevent breaking changes. Drash’s master branch tries to keep up with the latest Deno code (including deno_std) and is subject to Deno’s “disruptive renames” as stated in deno_std.

Quickstart

Create app.ts

import Drash from "https://deno.land/x/drash@v0.8.3/mod.ts";

class HomeResource extends Drash.Http.Resource {
  static paths = ["/"];
  public GET() {
    this.response.body = "Hello World!";
    return this.response;
  }
}

let server = new Drash.Http.Server({
  address: "localhost:8000",
  response_output: "text/html",
  resources: [HomeResource]
});

server.run();

… and run app.ts

$ deno --allow-net --allow-env app.ts

Deno server started at localhost:8000. Press CTRL+C to quit.

For a more complicated application, try out the Hello World tutorial series!