1.2.7 • Published 3 months ago

wint-js v1.2.7

Weekly downloads
-
License
-
Repository
github
Last release
3 months ago

Wint

Wint is a collection of high performance, heavily optimized URL routers for building web frameworks and applications.

Wint is compatible for every runtime that does support the Function constructor such as Bun, Node or Deno.

Features

All routers support wildcard and URL parameters matching.

API

Routers have three common methods.

/**
 * Add a route handler.
 */
put(method: string, path: string, handler: T): this;

/**
 * Find the matching item. Use after calling the `build` function.
 */
find(c: Context): T | null;

/**
 * Build the `find` function for the router.
 */
build(): this;

The build function must be called before calling find.

Routers

Currently two routers are supported.

Basic router

This router matches the URL with a radix tree.

The difference between this and other radix tree routers such as radix3 and @medley/router is that the matcher is compiled ahead of time, which brings a performance advantage.

import Wint from 'wint-js';

// Create and add routes
const wint = new Wint<() => string>()
    .put('GET', '/', () => 'Hi')
    .put('POST', '/json', () => '{}')
    .put('ALL', '/', () => 'Not found')
    .build();

// This is designed to be compatible with the `Request` object
wint.find({
    method: 'POST',
    path: 'json' // Path should slice the first slash character
}); // () => '{}'

Turbo router

Turbo router matches much faster than basic router but does not support ALL method handler.

import Wint from 'wint-js/turbo';

// Create and add routes
const wint = new Wint<() => string>()
    .put('GET', '/', () => 'Hi')
    .put('POST', '/json', () => '{}')
    .build();

// This is designed to be compatible with the `Request` object
wint.find({
    method: 'POST',
    url: 'http://localhost:3000/json'
}); // () => '{}'
1.2.7

3 months ago

1.2.6

4 months ago

1.2.5

4 months ago

1.2.4

4 months ago

1.2.3

5 months ago

1.2.2

5 months ago

1.2.0

5 months ago

1.1.0

5 months ago

1.1.9

5 months ago

1.1.8

5 months ago

1.1.7

5 months ago

1.1.6

5 months ago

1.1.5

5 months ago

1.1.4

5 months ago

1.1.3

5 months ago

1.2.1

5 months ago

1.1.2

5 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago