aircode-router

0.5.1 • Public • Published

AirCode Router

The official router for AirCode.

Usage

💡 To use this extension, you need to set EXPERIMENTAL_ROUTE=1 to enable path router first.

Add dependency:

Suppose your cloud function is named hello:

const {Router} = require('aircode-router');

const router = new Router({
  prefix: '/hello',
});

router.all('/users/:id', (params, context, next) => {
  return {
    params,
  };
});

module.exports = router.routes();

Then if you visit: /hello/users/yvo, you will get the userId "yvo" in params.

{
  "params": {
    "id": "yvo"
  }
}

💡 For debugging purposes, you can set the x-mock-route request header to simulate the route's path.

Router API

This router extension is developed based on @koa/router, and its API is fully compatible with @koa/router. The only exception is that the function parameters have been adjusted to comply with the AirCode cloud function specifications(with params as first parameter, and context as the second parameter).

You can find the API documentation here and seamlessly utilize most of the methods: API Reference

Readme

Keywords

none

Package Sidebar

Install

npm i aircode-router

Weekly Downloads

1

Version

0.5.1

License

MIT

Unpacked Size

7.18 kB

Total Files

4

Last publish

Collaborators

  • spritejs