Skip to content

Thesephi/oak-routing-ctrl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"}'

About

TypeScript Decorators for building API with the oak framework (jsr:@oak/oak)

Topics

Resources

License

Stars

Watchers

Forks