Create handlers for Deno.serve. Powered by functional composition and the URL Pattern API.
Attributes
Includes Deno configuration
Repository
Current version released
a year ago
composium
Powered by
functional composition and
the
URL Pattern API,
composium
has become the most flexible routing framework in the world. Through
its composability it can serve perfectly as a generic, abstract and
minimal layer for your own back-end framework.
URL Pattern
The best way to learn and test the URL Pattern API is Zaubrik’s free URL Pattern User Interface.
Documentation
deno doc https://deno.land/x/composium/mod.ts
Example
import { Context, createDefaultHandler, createGetRoute } from "./mod.ts";
function welcome<C extends Context>(ctx: C) {
const name = ctx.result.pathname.groups.name || "nobody";
ctx.response = new Response(`Welcome, ${name}!`);
return ctx;
}
const route = createGetRoute({ pathname: "/{:name}?" })(welcome);
const handler = createDefaultHandler(route);
Deno.serve(handler);
// curl http://localhost:8080/Joe
// Welcome, Joe!