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
Dependencies
std
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,
listen,
} from "./mod.ts";
function welcome(ctx: Context) {
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);
await listen(handler)({ port: 8080 });
// curl http://localhost:8080/Joe
// Welcome, Joe!