loading...
Cover image for What Makes Drash Different?

What Makes Drash Different?

drash_land profile image Drash Land ・4 min read

Hey, my name is Edward Bebbington. I am one of the maintainers for Drash Land and all of its projects. Here, I am going to talk about what makes Drash different and how it stands out when compared to other frameworks.

Table of Contents

What Makes Drash Different?

With so many frameworks already released in the Deno community, it can be hard to differentiate all of them. There are many that resemble popular frameworks like ExpressJS and Koa. Drash, on the other hand, is different. It doesn't resemble any of the Node frameworks and some might say it's the complete opposite of Express.

Deno was built to fix design mistakes and avoid certain things that Node used. One of those things is NPM. With this in mind, Drash sought to be different as well through its syntax and use of HTTP resources.

Syntax

You may notice Drash's syntax to be different than what you're used to using and seeing. Drash is very different than Node and Deno frameworks in terms of its syntax. Where Deno is different than Node, Drash aims to be different than Express or Koa. Unlike other frameworks, Drash utilizes resources and a full class-based system. This means it doesn't use app.get((req, res)). Instead, it uses this.request and this.response inside of the resource class, which is where your "routes" (aka paths) are also defined. As a result, this follows the MDN specs of HTTP Resources.

Furthermore, Drash takes a namespace approach with all of its data members being exposed under the Drash namespace. This is very different in terms of how a web application might be built inside of Node and Deno. Drash is a true object-oriented framework with the MDN as a backbone.

Resources

If you are familiar with Express, Laravel, or generally the MVC architecture, you might be familiar to routes and controllers. In Drash, a resource defines both in the same class. The resource is a class that handles requests for the HTTP verbs (e.g., GET, POST, DELETE, PUT) with each verb being its own request handler inside of the class. On top of this, the paths (or routes if it's easier) that a resource should handle are defined in that same class. An example of a resource is below:

// File: users_resource.ts

import { Drash } from "https://deno.land/x/drash/mod.ts";

export class UsersResource extends Drash.Http.Resource {

  static paths = ["/users", "/user:id"];

  public GET() {
    const userId = this.request.getUrlQueryParam("id");
    if (!userId) {
        this.response.body = "Return all users";
        return this.response
    }
    this.response.body = "The user";
    return this.response.body;
  }

}

And plugging the resource into your server is super simple:

import { Drash } from "https://deno.land/x/drash/mod.ts";
import { UsersResource } from "./users_resource.ts";

const server = new Drash.Http.Server({
  resources: [UserResource] // The UsersResource will now be registered in the server
});

server.run({
  hostname: "localhost",
  port: 1667
});

Drash Compared To Other Frameworks

You've probably figured out by now that Drash isn't like existing Node and Deno frameworks. So what truly makes Drash stand out from Express, Oak, MandarineTS, or any other framework listed under Deno's Third Party Modules (search for "framework" when looking at the Third Party Modules)?

Well, let's compare Drash to Node and Deno frameworks.

Deno Frameworks

Some well-known frameworks in the Deno community are Oak (similar to Express), MandarineTS (decorator framework), and Opine (similar to Express).

There are plenty of frameworks that are similar (or close to being an exact port) to Express. It can feel a little overwhelming. What makes Drash stand out is Drash isn't like Express. Drash is unique. Like I mentioned above, Drash has reasons for certain implementations. The problem with Deno frameworks is that most of them are similar -- taking Express and Koa as inspiration. Whilst it's good to have a variety of frameworks, it's also good that each one is different to cater to different people's preferences.

Node Frameworks

Drash isn't like any Node framework. It's something new and unique.

Drash's Goals

Drash aims to be different and unique -- helping people develop software with confidence through a clean and easy-to-use syntax. There were many problems for Drash in the early stages of its development (around 2018-2019). This was due to it trying to be similar to Express. What Drash has become has solved these problems and was introduced as a unique alternative to the Deno community.


I hope this was insightful. With there being many frameworks for Deno, it can be hard to differentiate all of them in a quick and clear way. Although this article doesn't go into detail about other frameworks, I hope this article helps you understand Drash more.

-- Edward


Want to start developing using Drash? Check out its documentation pages here!

Want to know why Drash was built? One of the founders of Drash wrote an article about it here.

Posted on by:

Discussion

markdown guide