Skip to main content

routing-controllers -like library for the oak framework (jsr:@oak/oak)

Works with
It is unknown whether this package works with Bun
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Node.js
This package works with Deno
It is unknown whether this package works with Browsers
JSR Score
100%
Published
3 months ago

oak-routing-ctrl

Built with the Deno Standard Library

routing-controllers -like library for the Oak framework (jsr:@oak/oak) 🚗 🐿️ 🦕

@Controller("/api/v1/pokemon")
class MyPokedex {
  @Get("/:id")
  viewEntry(ctx) {
    if (ctx.params.id === "0025") return "Pikachu";
  }
}

Forewords

If you're familiar with the npm library routing-controllers, you'll find yourself very much at home.

However, please note that this libray is not meant to be a drop-in replacement for routing-controllers, as it attempts to conform to TC39 Decorators proposal which doesn't support Method Parameter Decorator yet. There's currently no plan to support TypeScript "experimental" decorators, but if you feel strongly for it, please feel free to fork this repo!

Installation

Prerequisite: Deno

deno add @dklab/oak-routing-ctrl

Example Usage

// main.ts

import { Application } from "jsr:@oak/oak";
import { useOakServer } from "jsr:@dklab/oak-routing-ctrl";
import { MyController } from "./MyController.ts";

const app = new Application();
useOakServer(app, [MyController]);
await app.listen({ port: 1993 });
// MyController.ts

import {
  Controller,
  ControllerActionArgs,
  Post,
} from "jsr:@dklab/oak-routing-ctrl";

@Controller()
export class MyController {
  @Post("/tell/:whom")
  @ControllerActionArgs("body")
  say(body, ctx) {
    const { note } = body;
    console.log(`telling ${ctx.params.whom} that "${note}"`);
  }
}
deno run -A main.ts
curl localhost:1993/tell/Alice -d'{"note": "Bob is waiting"}'
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @dklab/oak-routing-ctrl

Import symbol

import * as mod from "@dklab/oak-routing-ctrl";

Add Package

npx jsr add @dklab/oak-routing-ctrl

Import symbol

import * as mod from "@dklab/oak-routing-ctrl";

Add Package

yarn dlx jsr add @dklab/oak-routing-ctrl

Import symbol

import * as mod from "@dklab/oak-routing-ctrl";

Add Package

pnpm dlx jsr add @dklab/oak-routing-ctrl

Import symbol

import * as mod from "@dklab/oak-routing-ctrl";

Add Package

bunx jsr add @dklab/oak-routing-ctrl

Import symbol

import * as mod from "@dklab/oak-routing-ctrl";