routery

A router that uses pathor to match and parse parametric URLs

Usage no npm install needed!

<script type="module">
  import routery from 'https://cdn.skypack.dev/routery';
</script>

README

routery

A router that uses pathor to match and parse parametric URLs

Installation

npm i routery

Usage

import {Router} from 'routery';

// `Message` is an example type of custome data
const router = new Router<Message>({
  // Below is default options, if it match your situation, just let options empty.
  single: '+', // single level wildcard for topic compiling
  multiple: '#', // multi level wildcard for topic compiling
  separators: '/', // path seperator for URL matching
});

// path style see: https://github.com/taoyuan/pathor
router.add('/a/:b/:others*', (params: Record<string, any>, data: Message) => {
  console.log(params);
  // =>
  // {
  //   b: 'foo',
  //   others: ['bar', 'hello'],
  // }
  console.log(data);
  // => message
  // {...}
});

// ...

router.handle('/a/foo/bar/hello', message);

path format see pathor

Builtin Topic Options

MQTT (default)

import {MqttTopic} from 'routery';

new Router(MqttTopic);

AMQP

import {AmqpTopic} from 'routery';

new Router(AmqpTopic);