Introduction
Welcome! We're glad you're here!
What is Drash?
Drash is a microframework for building JavaScript HTTP applications. It can be used in Deno, Node, Cloudflare Workers, Bun, and any other environment that can run JavaScript. It can also be used alongside your current JavaScript HTTP application — giving you the ability to reroute some requests to Drash or migrate smoothly and safely to a complete Drash solution.
You can learn more about Drash and its concepts under the Concepts section in the left sidebar.
Migration Guide
Apologies! For your awareness, we are still working on the migration guide from v2 to v3, so stay tuned!
Quickstart Guide
Fork on Deno Deploy
You can fork the Drash playground on Deno Deploy here. The full URL is written below if you want to copy it:
https://dash.deno.com/playground/drash-v3x-beta-1
Copy and Paste Code
Given this is the quickstart section, we are assuming you know how to run the code below after copying and pasting it somewhere. If you need some help, hit us up in Discord.
import {
Chain,
Resource,
} from "https://esm.sh/@drashland/drash/modules/chains/RequestChain/mod.native.js";
// import {
// Chain,
// Resource,
// } from "npm:@drashland/drash/modules/chains/RequestChain/mod.native.js";
// Create a resource
class Home extends Resource {
paths = ["/"];
GET(request: Request) {
console.log(`Received request: ${request.url}`);
return new Response(
`Hello from Home.GET()! (written at ${new Date()})`,
);
}
}
// Build the chain and add the resource
const chain = Chain
.builder()
.resources(Home)
.build();
// Define server variables for reuse below
const hostname = "localhost";
const port = 1447;
// Create and start the server
Deno.serve({
hostname,
port,
onListen: ({ hostname, port }) => {
console.log(`\nDrash running at http://${hostname}:${port}`);
},
handler: (request: Request): Promise<Response> => {
// Pass the request to the chain
return chain
.handle<Response>(request)
.catch((error) => {
if (request.url.includes("favicon")) {
return new Response();
}
return new Response(
"Sorry, but we hit an error!",
{
status: 500,
statusText: "Internal Server Error",
},
);
});
},
});
Features
- Ships with zero dependencies 1
- Runtime agnostic 2
- Extensively documented so you can develop with confidence 3
- Hella typed so you can use it with your TypeScript codebase
- Built to work as an ECMAScript Module and a CommonJS Module
- Dynamic paths (e.g.,
/users/:id
) 4
Notes
- We're all about this zero deps life. porsager/postgres knows what's up.
- Drash v3.x was developed using Deno 1.34.3. It was tested using Deno 1.34.3, Node v18.14.2, Cloudflare Workers (using Node v18.x) Bun v0.x. If your environments are using other versions, then your experience may vary since we have no control over runtime version incompatibilities. However, we're here to help, so please hit us up in Discord!
- You know we document! If you are new to Drash Land software, we want you to know we strive to make sure you can develop with confidence. This is why we document and explain everything we can. If something doesn't make sense, please let us know by filing an issue!
- Drash has modules that use
URLPattern
or a polyfill for it. This way you can choose a module that works in your chosen runtime environment.