Drash - A Unique Framework
Tags: deno, drash, typescript, webdev
Published: 2020-07-14 17:26:13

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?](#what-makes-drash-different)
    - [Syntax](#syntax)
    - [Resources](#resources)
- [Drash Compared To Other Frameworks](#drash-compared-to-other-frameworks)
    - [Deno Frameworks](#deno-frameworks)
    - [Node Frameworks](#node-frameworks)
- [Drash's Goals](#drashs-goals)

## 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](https://expressjs.com/) and [Koa](https://koajs.com). Drash, on the other hand, is different. It doesn't resemble any of the [Node frameworks](http://nodeframework.com/) and some might say it's the complete opposite of Express.

Deno was built to [fix design mistakes](https://www.youtube.com/watch?v=M3BM9TB-8yA&t=1310s) and avoid certain things that Node used. One of those things is [NPM](https://www.npmjs.com/). 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](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Identifying_resources_on_the_Web).

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](https://laravel.com/), 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:

```typescript
// 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:

```typescript
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](https://oakserver.github.io/oak/), [MandarineTS](https://mandarineframework.gitbook.io/mandarine-ts/), or any other framework listed under Deno's [Third Party Modules](https://deno.land/x) (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](https://github.com/asos-craigmorten/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](https://drash.land/drash)!

Want to know why Drash was built? One of the founders of Drash wrote an article about it [here](https://dev.to/drash_land/why-was-drash-built-4bob).