Drash
A REST microframework for Deno with zero dependencies.
Table of Contents
Quick Start
// File: app.ts
import { Drash } from "https://deno.land/x/drash@v1.0.0/mod.ts";
class HomeResource extends Drash.Http.Resource {
static paths = ["/"];
public GET() {
this.response.body = "Hello World! deno + Drash is cool!";
return this.response;
}
}
const server = new Drash.Http.Server({
response_output: "text/html",
resources: [HomeResource]
});
server.run({
hostname: "localhost",
port: 1447
});
console.log("Server listening: http://localhost:1447");
$ deno run --allow-net app.ts
Server listening: http://localhost:1447
$ curl localhost:1337
Hello World! deno + Drash is cool!
Documentation
Features
- Content Negotiation
- Static Path Routing
- Regex Path Routing
- Middleware
- Body Handling: application/json
- Body Handling: application/x-www-form-urlencoded
- Body Handling: multipart/form-data
- Handling Path Params
- Handling URL Query Params
- Console Logging
- File Logging
Why Use Drash?
Drash is designed to help you build your projects quickly with the ability to scale. You can build an API, a web app, an SPA (like the documentation pages), or even a static HTML site. How you use Drash is up to you, so it can be everything you need and nothing you don’t — like a DRASH tent.
Drash takes concepts from the following:
- Flask — being micro and extensible
- Laravel — use of similarly styled middleware
- Tonic — use of resources
- RESTful principles — content negotiation, HTTP verbs, URIs, etc.
Thrown into the mix is Drash’s own concepts such as:
- Documentation-driven development
- Test-driven development
- Lowering barriers to usage
Drash does not force you to use all of its code. You can pick and choose which data members you want/need and use them however you deem fit. For example, Drash comes with a console logger and a file logger. If you only want these, then you only import these into your non-Drash project. How you use it is really up to you.
Example Drash App
The example_app
directory contains an example Drash application. You can run it using deno
locally.
- Install deno.
curl -fsSL https://deno.land/x/install/install.sh | sh -s v1.0.0
- Run the Drash application using
deno
.
deno run --allow-net --allow-read --allow-env https://deno.land/x/drash@v1.0.0/example_app/app_1.ts
- Make the following request:
GET /
.
curl --request GET localhost:1447
"GET request received!"
- Make the following request
GET /coffee/17
.
curl --request GET localhost:1447/coffee/17
{"name":"Light"}
- Make the following request
POST /
.
curl --request POST localhost:1447
"POST request received!"
- Make the following request
PATCH /
(with verbose flag). This method is not defined in theHomeResource
class, so you should receive a405
response.
curl --request PATCH --verbose localhost:1447
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 1447 (#0)
> PATCH / HTTP/1.1
> Host: localhost:1447
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 405 Method Not Allowed
< content-type: application/json
< content-length: 20
<
* Connection #0 to host localhost left intact
"Method Not Allowed"* Closing connection 0
Contributing
Contributors are welcomed!
Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.
License
By contributing your code, you agree to license your contribution under the MIT License.