radrou

Fast as f**k radix tree router

Usage no npm install needed!

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

README

RadRou

Fast as f**k radix tree router ported and adapted from httprouter (which is written in go). I modified this so it can take an arbitrary value instead of a handler function, so it can be more generic and more easiley adapted to other use cases.

Installation

npm i radrou
yarn add radrou

Usage

import { Node } from 'radrou';

interface Value {
  handler: (req: IncomingMessage, res: ServerResponse): Promise<void>
  validate: { ... }
}

const tree = new Node<Value>()

tree.add('/posts/:id', {
  handler: (req,res) => {
    // your logic or whatever value
  },
  validate: { ... }
})

tree.find('/posts/123') // => { value: { handler, validate }, params: [{ key: 'id', value: '123 }] }