All Projects → swimlane → Trafficlight

swimlane / Trafficlight

Licence: mit
🚦 Flexible NodeJS Routing Decorators for API Routing

Programming Languages

typescript
32286 projects
es7
32 projects

Projects that are alternatives of or similar to Trafficlight

Koa Dec Router
An ES6 decorator + class based router, support inherit, override, priority, auto load controllers, etc.
Stars: ✭ 19 (-72.46%)
Mutual labels:  koa, koa2, decorators
Koa2 Api Scaffold
一个基于Koa2的轻量级RESTful API Server脚手架。
Stars: ✭ 694 (+905.8%)
Mutual labels:  express, koa, koa2
Vue Chat
👥Vue全家桶+Socket.io+Express/Koa2打造一个智能聊天室。
Stars: ✭ 887 (+1185.51%)
Mutual labels:  express, koa, koa2
Postgraphile
GraphQL is a new way of communicating with your server. It eliminates the problems of over- and under-fetching, incorporates strong data types, has built-in introspection, documentation and deprecation capabilities, and is implemented in many programming languages. This all leads to gloriously low-latency user experiences, better developer experiences, and much increased productivity. Because of all this, GraphQL is typically used as a replacement for (or companion to) RESTful API services.
Stars: ✭ 10,967 (+15794.2%)
Mutual labels:  express, koa, koa2
Github Ranking
🔍GitHub不同语言热门项目排行,Vue.js做页面展示
Stars: ✭ 160 (+131.88%)
Mutual labels:  express, koa, koa2
Cool Admin Api
cool-admin-api 是基于egg.js、typeorm、jwt等封装的api开发脚手架、快速开发api接口
Stars: ✭ 188 (+172.46%)
Mutual labels:  express, koa, koa2
Blog Service
blog service @nestjs
Stars: ✭ 188 (+172.46%)
Mutual labels:  express, koa, koa2
Vue Socket.io Chat
💬 TypeScript + Vue + Express/Koa + Socket.io
Stars: ✭ 61 (-11.59%)
Mutual labels:  express, koa, koa2
Koa Weixin Jssdk
koa weixin jssdk middleware
Stars: ✭ 7 (-89.86%)
Mutual labels:  koa, koa2
Vue Koa Demo
🔰A simple full stack demo(CSR & SSR & Docker Support) written by Vue2 & Koa2(Koa1 verson also completed)
Stars: ✭ 730 (+957.97%)
Mutual labels:  koa, koa2
Nodeclub Koa
use koa to rewrite nodeclub
Stars: ✭ 18 (-73.91%)
Mutual labels:  koa, koa2
Koa Passport
Passport middleware for Koa
Stars: ✭ 748 (+984.06%)
Mutual labels:  koa, koa2
Node Typescript Koa Rest
REST API boilerplate using NodeJS and KOA2, typescript. Logging and JWT as middlewares. TypeORM with class-validator, SQL CRUD. Docker included. Swagger docs, actions CI and valuable README
Stars: ✭ 739 (+971.01%)
Mutual labels:  koa, koa2
Koa Generator
Koa' application generator for 1.x and 2.x( Express-style and support all middlewares include async/await )
Stars: ✭ 929 (+1246.38%)
Mutual labels:  koa, koa2
Cykspace Node
博客后台服务~~ 👉👉 http://www.cykspace.com
Stars: ✭ 23 (-66.67%)
Mutual labels:  koa, koa2
Mysrv
Yet another Node.js web framework, based on koa.js 又一个 Node.js MVC 框架,基于Koa2
Stars: ✭ 10 (-85.51%)
Mutual labels:  koa, koa2
Kona
a node.js service framework built on koa.js (generators)
Stars: ✭ 23 (-66.67%)
Mutual labels:  express, koa
Angela
🙂angela (安其拉):react ssr router redux; react同构框架
Stars: ✭ 15 (-78.26%)
Mutual labels:  express, koa
Vue Qq
🎨 Vue family bucket with socket.io and express/koa2 , create a web version of mobile QQ, supporting real-time group chat, real-time private chat, special care, shielding chat, smart IP geographic location, real-time display temperature and other QQ core functions
Stars: ✭ 861 (+1147.83%)
Mutual labels:  express, koa2
Koatty
Koa2 + Typescript = Koatty. Use Typescript's decorator implement IOC and AOP.
Stars: ✭ 67 (-2.9%)
Mutual labels:  koa, koa2

Trafficlight 🚦

Codacy Badge Codacy Badge Build Status npm version

A flexible NodeJS Routing Decorators for API Routing. Features include:

  • Built for KOA2
  • Bring-your-own router
  • Bring-your-own body parser
  • TypeScript and ES7 Support
  • DI compatible

Usage

Building

npm run build

Install

npm i trafficlight --S

Note: You must have reflect-metadata installed as a peer dependency

Setup KOA

import 'reflect-metadata'; /* Must be singleton */
import * as Koa from 'koa';
import * as Router from 'koa-router';
import * as body from 'koa-better-body';

import { ProfileController } from './controllers';
import { bindRoutes } from 'trafficlight';

export function setupKoa() {
  const app = new Koa();

  app.use(body());
  buildRoutes(app);
  app.listen(3000);

  return app;
}

function buildRoutes(app) {
  const routerRoutes = new Router();

  // any router can be used, we support koa-router out of the box
  bindRoutes(routerRoutes, [ProfileController]);

  // if you are using with some sort of DI system you can pass
  // a third parameter callback to get the instance vs new ctrl.
  // bindRoutes(routerRoutes, [ProfileController], (ctrl) => injector.get(ctrl));

  app.use(routerRoutes.routes());
  app.use(routerRoutes.allowedMethods());
}

Decorate the controller

import { Controller, Get, Use, Param, Body, Delete, Put, Post, QueryParam } from 'trafficlight';

@Controller('/profile')
@Use(someMiddleware)
export class ProfileController {

  @Get()
  getAll(@QueryParam('filter') filter) {
    // return []
  }

  @Get('/:id')
  @Use(someMiddleware)
  getOne(@Param('id') id) {
    // return {}
  }

  @Post()
  create(@Body() body) {
    // return {}
  }

  @Post('/:id/upload')
  upload(@Param('id') id, @File() file) {
    // return {}
  }

  @Put('/:id')
  update(@Param('id') id, @Body() body) {
    // return {}
  }

  @Delete('/:id')
  destroy(@Param('id') id) {
    // return success
  }

}

API

  • bindRoutes(routerTable, controllers, getter) - Binds the controller to the route table.
  • Controller(url?) - Top level controller decorator. Optional root url
  • Route(method, url?) - Abstract method decorator, accepts method type, url
  • Get(url?) - Http GET method, accepts URL
  • Post(url?) - Http Post method, accepts URL
  • Put(url?) - Http Put method, accepts URL
  • Delete(url?) - Http Delete method, accepts URL
  • Params() - Returns all the parameters passed in the request
  • Param(val) - Returns a specific parameter passed in the request
  • File() - Returns a single file in the request body
  • Files() - Returns all files in the request body
  • QueryParams() - Returns all the query parameters passed in the request url as an object
  • QueryParam(val) - Returns a specific query parameter passed in the request url
  • Ctx() - Returns the KOA context object
  • Req() - Returns the Node request object
  • Request() - Returns the KOA request object
  • Res() - Returns the Node response object
  • Response() - Returns the KOA response object
  • Body() - Returns the request body object
  • Fields() - Returns the request fields object
  • Use() - Middleware decorator for class and functions

Special return types

Since typescript doesn't allow decorators on return types. Certain type has been added to indicate and allow for file download.

  • FileDownload: {fileName: string, mimeType: string, stream: ReadStream}

Inspiration

Credits

trafficlight is a Swimlane open-source project; we believe in giving back to the open-source community by sharing some of the projects we build for our application. Swimlane is an automated cyber security operations and incident response platform that enables cyber security teams to leverage threat intelligence, speed up incident response and automate security operations.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].