Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Create well-structured and organized class-based controllers for Koa 2 using TypeScript

Notifications You must be signed in to change notification settings

justblender/koa-routing-controllers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

koa-routing-controllers

Create highly performant and well-structured class-based controllers for Koa 2 using TypeScript.

NOTE: This is a "work in progress" project and many features are currently absent. Pull requests are welcome! :)

Installation

  1. Install this package:

npm install koa-routing-controllers

  1. Install reflect-metadata package:

npm install reflect-metadata

and make sure to import it before using this package:

import "reflect-metadata"
  1. Make sure you have experimentalDecorators and emitDecoratorMetadata options enabled in tsconfig.json:
"emitDecoratorMetadata": true,
"experimentalDecorators": true,

Usage

import "reflect-metadata";

import { Controller, Get, Param, createKoaServer } from "koa-routing-controllers";

@Controller()
export class HelloWorldController {
  @Get("/")
  helloWorld() {
    return "Hello, world!";
  }

  @Get("/:name")
  greetByName(@Param("name") name: string) {
    return `Hello, ${name}!`;
  }
}

createKoaServer({
  controllers: [
    HelloWorldController
  ]
}).listen(8080, () => {
  console.log("Listening on http://localhost:8080");
});

Roadmap

  • Add needed decorators
  • Add more type coverage
  • Add support for injectable parameters
  • Add support for scoped middlewares
  • Add support for body/query validation
  • Add documentation

About

Create well-structured and organized class-based controllers for Koa 2 using TypeScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published