@curveball/router

Router middleware for Curveball

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
124Jun 15, 2021Jul 1, 2018Minified + gzip package size for @curveball/router in KB

Readme

Curveball Router

This package is a simple router for Curveball.

Installation

npm install @curveball/router

Getting started

The simplest, and recommended form works as follows:

import { Application } from '@curveball/core';
import router from '@curveball/router';

const app = Application();
app.use(
  router('/foo/:id', ctx => {
    // the 'id' is available via ctx.params.id
  })
);

It's also possible to do per-method routing, using the following syntax.

import { Application } from '@curveball/core';
import router from '@curveball/router';

const app = Application();
app.use(
  router('/foo/:id')
    .get( ctx => { /* GET requests */ })
    .post( ctx => { /* POST requests */ })
);

You can either specify 1, or multiple middlewares. The following example runs 2 fictional middlewares on a route.

const app = Application();

const route = router(
  '/foo/:id',
  myAuthMiddleware,
  myBodyparser,
  ctx => {
    ctx.response.body = 'success!';
  }
);

app.use(route);

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.