0.5.1 ā€¢ Published 9 months ago

aircode-router v0.5.1

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

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

0.5.1

9 months ago

0.5.0

9 months ago

0.4.0

9 months ago

0.3.0

9 months ago

0.2.0

9 months ago

0.1.0

9 months ago