Repository
Current version released
3 years ago
Raptor
Simple and small, router handler for Deno server and Deploy.
Raptor implemented to nhttp
Features
- Middleware support.
- Sub Router support.
Usage
import { serve } from "https://deno.land/std@0.118.0/http/server.ts";
import { raptor } from "https://deno.land/x/raptor@0.0.2/mod.ts";
serve(
raptor()
.make("GET", () => new Response("Hello World"))
.make("GET/hello/:name", (ctx) => new Response(`Hello ${ctx.params.name}`))
.resolve,
);
console.log("Raptor was here !!");
Run
deno run --allow-net file.ts
and visit http://localhost:8000
with path /
and /hello/yourname
Make
Make everything with raptor().make(verb, ...fns)
.
the verb is =>
GET | POST | DELETE | PUT | PATCH | OPTIONS | HEAD | ANY | ROUTER | WARE
and
path.
Make Method Handlers
serve(
raptor()
.make("GET/hello/:name", (ctx) => new Response(`Hello ${ctx.params.name}`))
.resolve,
);
Make Global Middleware
serve(
raptor()
.make("WARE", (ctx, next) => {
ctx.foo = "foo";
return next();
})
.make("GET/hello", (ctx) => new Response(`Hello ${ctx.foo}`))
.resolve,
);
If Inline Middleware
serve(
raptor()
.make("GET/hello", (ctx, next) => {
ctx.foo = "foo";
return next();
}, (ctx) => {
return new Response(`Hello ${ctx.foo}`);
})
.resolve,
);
Make Sub Router
const router = raptor.createRouter();
router.make("GET/user", () => new Response("Hello from router"));
serve(
raptor()
.make("ROUTER/api/v1", [router])
.resolve,
);
// visit http://localhost:8000/api/v1/user