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

routerling

v0.0.1

Published

Extremely Stupid Simple, Blazing Fast, Get Out of your way immediately Microframework for building Python Web Applications.

Downloads

2

Readme

Do Not Install - Still in Development

Routerling

A new born baby router on it's way to being a web development platform. Routerling is a router multiplexer built with 1 goal in mind.

  • Make it stupid simple to build high performance web applications

How?

Routerling has only ONE API you need to learn - Router. The API is also deliberately made consistent across the 3 different supported languages [Golang, Python, Typescript/JavaScript]. See Similarities

import Router, { HttpRequest, ResponseWriter, Context } from 'routerling';

import Container from './dependency.injection.example.etc.ts'; //optional


router = new Router();


router.before('*', async (req: HttpRequest, res: ResponseWriter, ctx: Context) => {
    //inversify or typedi or any other DI container if DI is desired
    const baseRepository: BaseRepository = Container.get('my-dependency')

    return ctx.baseRepository = baseRepository;
});


router.get('/users/:id', async(r: HttpRequest, w: ResponseWriter, c: Context) => {
    if(c.skip === true) return 
})


router.after(['/users/*', '/users'], async() => {
    //no-op
});

router.post('/users', async(r: HttpRequest, w: ResponseWriter, c: Context) => {
    //the order of the calls don't mean squat so go crazy
});


//host, port, debug
router.listen("localhost", 8081, true);


//-------------------------- Another Example -------------------------------------//
import { Router, Request, Response, Context } from 'routerling';


Router.before('*', (req: Request, res: Response, ctx: Context) => {
    const authorizationToken: string = request.headers.CONTENT_TYPE

    //for customer headers use the following syntax
    authorizationToken = request.headers.get('X-Auth-Token');
    if(authorizationToken) {
        return ctx.set("myPersonalDBToHoldStuff", authorizationToken)
    }

    //you can abort with the helper abort method, return is not required but used for consistent interface with golang routex
    return req.abort(401, {message: 'Unauthorized'})

    //raising an exception will also prevent further processing of the request
    //to prevent routex from sending back 500, use a custom HttpException i.e. see how to create one or use a library {message, code}
    throw new Error("something happened")
})

import (
    "fmt"
    "strings"
    rg "github.com/rayattack/routerling"
)

func init(){
    //do whatever you fancy here...
}

func main(){
    const router := rg.Router()
    router.BEFORE("*", func(r rg.HttpRequest, w *rg.ResponseWriter, ctx: *rg.Ctx){
        fmt.Println("I will be called before every request is handled because of my wildcard")
    })

    router.AFTER("customers/:id", func(r rg.HttpRequest, w *rg.ResponseWriter, ctx: *rg.Cache) error {
        authorizationToken := r.headers.get("X-Auth-Token")
        token := strings.Split(authorizationToken, " ")
        if(len(token) == 2) {
            ctx.Set("some-custom-key-as-my-db", token)
            return nil
        }
        //this will abort
        return r.abort()

        //this will
        return fmt.Errorf("This is some error alright...")
    })

    router.GET("/customers/:id", func(req *routerling.Request, res routerling.Response, ctx routerling.Context){
        //go crazy here...
    }, "optional-name-for-this")

    router.listen("localhost", 8701, true)
}

Request Object

Documentation coming soon.

Response Object

Documentation coming soon.

Context Object

Documentation coming soon.

Example Application

Documentation coming soon.

FAQs

  • What happens if I try to register the same route with two different functions?
    • Routex will throw an error you can only register a path with one handler
  • What happens if I use a specific method like GET for '/customers' then a generic one also Router.route('/customers')
    • Your specific function will override the non-specific one for the method that matches and use the function for all others
  • So how does the all handler work?
    • Routex will call the all handler after nothing matches and you also can not define more than one handler for the wildcard route
  • You can have multiple before and after functions but only one handler routes use strict equality checking when assigning a function handler and multiplexing when looking for matches

Similarities

CAPITALS are used for router handlers to match HTTP convention, and also due Golang's private/public semantics. ResponseWriter and HttpRequest were also so named to match Golan interfaces and provide an ubiquitous experience across programming languages/environments.