See more information about the Raptor framework here: https://jsr.io/@raptor/framework.
Note
This is currently under heavy development and is not yet suitable for production use. Please proceed with caution.
To start using the router, simply install into an existing Raptor application via the CLI or import it directly from JSR.
deno add jsr:@raptor/router
Raptor is also available to import directly via JSR: https://jsr.io/@raptor/router
The built-in router operates similarly to standard Raptor middleware, enabling you to define routes using Web API standard URL patterns. For further details, visit mozilla.org/URLPattern.
import { Kernel, Context } from "jsr:@raptor/framework";
import { Router, Route, HttpMethod } from "jsr:@raptor/router";
const app = new Kernel();
const router = new Router();
const route = new Route({
name: "index",
method: HttpMethod.GET,
pathname: "/",
handler: () => 'Hello, Dr Malcolm!'
});
router.add(route);
app.add((context: Context) => router.handler(context));
app.serve({ port: 8000 });
Route parameter values are processed and available via the router's context object (context.params
) if they are found in the route's pathname. Make sure to import the router's Context
object, rather than the base Raptor Context
object.
import { Route, Context, HttpMethod } from "jsr:@raptor/router";
/* ... */
const route = new Route({
name: "person.read",
method: HttpMethod.GET,
pathname: "/person/:name";
handler: (context: Context) => {
const { name } = context.params;
return `Hello ${name}`;
}
});
Copyright 2024, @briward. All rights reserved. The framework is licensed under the MIT license.