npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-isomorphic-router

v1.0.1

Published

The fastest elegant modern amiable Koa.js Router ⚡.

Downloads

279

Readme

Koa Isomorphic Router


Build Status Coverage Status NPM version Code Size License PR's Welcome

The fastest elegant modern amiable Koa.js Router ⚡.

Features

  • 🦄 Based on top of Trek Router which inspired by Echo's Router.
  • 🚀 Faster than other Koa.js router solutions.
  • 💅🏻 Express-style routing (app.get, app.post, app.put, app.delete, etc.)
  • 🔥 Blaze and lightweight router.
  • ⚖️ Tiny Bundle: less than 2.5kB (gzip)
  • 🪁 Named URL parameters.
  • 🎯 Route middleware.
  • 🥞 Support router layer middlewares.
  • 📋 Responds to OPTIONS requests with allowed methods.
  • ⛔️ Support for 405 Method Not Allowed.
  • ❌ Support for 501 Path Not Implemented.
  • 🧼 Support trailing slash and fixed path by automatic redirection.
  • ✨ Asynchronous support (async/await).
  • 🎉 TypeScript support.

Note

Currently, this modules support 405 Method Not Allowed and 501 Path Not Implemented for 'static' routes only as you can see here.

As soon as possible when I get response here will support 'param' and 'match-any' routes.

For support RegExp in route path also I waiting for any response here.

Benchmarks

All Koa router solutions depend on path-to-regexp when our solution relies on the trek-router which has the best performance and not over the path-to-regexp only also on others such as (route-recognizer, route-trie, routington ...etc).

  • [x] See trek-router benchmarks (trek-router better perf. than path-to-regexp).
  • [x] See fastify benchmarks (koa-isomorphic-router better perf. than koa-router).

Installation

# npm
$ npm install koa-isomorphic-router
# yarn
$ yarn add koa-isomorphic-router

Usage

This is a practical example of how to use.

const Koa = require('koa')
const Router = require('koa-isomorphic-router')

const app = new Koa()
const router = new Router()

router
  .get('/product/:id', (ctx, next) => {
    ctx.body = { productId: ctx.params.id }
  })

app.use(router.routes())

app.listen(5050)

API

new Router(options?)

Create a new router.

| Param | Type | Description | | --- | --- | --- | | [options] | Object | | | [options.prefix] | String | prefix router paths | | [options.throw] | Boolean | throw error instead of setting status and header | | [options.notImplemented] | function | throw the returned value in place of the default NotImplemented error | | [options.methodNotAllowed] | function | throw the returned value in place of the default MethodNotAllowed error |

router.get|post|put|patch|delete|all(path, ...middlewares)

The http methods provide the routing functionality in router.

Method middleware and handlers follow usual Koa middleware behavior, except they will only be called when the method and path match the request.

// handle a GET / request.
router.get('/', (ctx) => { ctx.body = 'Hello World!' })

router.prefix(prePath)

Route paths can be prefixed at the router level:

// handle a GET /prePath/users request.
router
  .prefix('/prePath')
  .get('/users', (ctx) => { ctx.body = 'Hello World!' })

router.route(path)

Lookup route with given path.

// handle a GET /users request.
router
  .route('/users')
  .get((ctx) => { ctx.body = 'Hello World!' })

router.use(...middlewares)

Use given middleware(s). Currently, use middleware(s) for all paths of router isntance.

router.routes()

Returns router middleware which handle a route matching the request.

Support

If you have any problem or suggestion please open an issue here.

Call for Maintainers/Contributors

This module is a attempt to craft an isomorphic fast Router, from/to Koa.js community. So, don't hesitate to offer your help ❤️.

Contributors

| Name | Website | | --------------- | ------------------------------- | | Imed Jaberi | https://www.3imed-jaberi.com/ |

License


MIT © Imed Jaberi