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

routing-master

v1.0.4

Published

Simplify route management, define routes effortlessly, attach interceptors, integrate with Axios/Fetch. Streamline routing, empower developers. Create efficient web apps. No more complex configurations. Embrace convenience.

Downloads

35

Readme

RoutingMaster

License

RoutingMaster is a powerful JavaScript package that simplifies route management and provides enhanced flexibility. It allows you to effortlessly define and name routes, attach interceptors to individual routes, and seamlessly integrate with popular HTTP clients like Axios or Fetch. By streamlining the process of handling routing, RoutingMaster empowers developers to create efficient and scalable web applications.

Features

  • Easy Route Definition: Define routes with ease using RoutingMaster's intuitive syntax and naming conventions.
  • Interceptor Attachments: Attach interceptors to specific routes to handle pre-processing or authentication logic.
  • Integration with Popular HTTP Clients: Seamlessly integrate with popular HTTP clients like Axios or Fetch to handle the actual requests.
  • Scalable and Efficient: Streamline your routing process for improved performance and scalability.
  • Simplified Configuration: Say goodbye to complex routing configurations and embrace the simplicity and convenience provided by RoutingMaster.

Installation

You can install RoutingMaster via npm:

npm install routing-master

Usage

Define your routes using RoutingMaster's simple syntax:

const routes = {
  home: () => ({
    path: '/',
    method: 'GET',
    // Additional configuration options here
  }),
  // Define more routes as needed
};

Attach interceptors to routes for handling pre-processing or authentication:

const routes = {
  home: () => ({
    path: '/',
    method: 'GET',
    interceptors: {
      request: [
        // Interceptor functions here
      ],
      response: [
        // Interceptor functions here
      ],
    }
  }),
  // Define more routes with interceptors
};

Define route parameters. Every parameter defined in the route path will be replaced by the value of the corresponding parameter in the params object. Parameters defined in params but not in the route path will be appended to the end of the route URL as query parameters or as body parameters, depending on the HTTP method.

const routes = {
  product: (id) => ({
    path: '/products/{id}',
    params: {id},
    method: 'GET',
  }),
  create: (params) => ({
    path: '/products/create',
    params,
    method: 'POST',
  }),
  // Define more routes with interceptors
};

The routing supports nested routes, allowing you to create hierarchical route structures. Nested routes are useful when you have a parent route that encapsulates child routes. The child routes inherit the interceptors from their parent route and have URLs that start with the parent route URL.

To define nested routes, you can include a children property in the route configuration object. Here's an example:

const routes = {
  users: () => ({
    path: '/users',
    method: 'GET',
    children: {
      edit: (id) => ({
        path: '/{id}/edit',
        method: 'PUT',
        // Additional configuration options for child route
      }),
     delete: (id) => ({
        path: '/{id}',
        method: 'DELETE',
        // Additional configuration options for child route
      })       
      // Define more child routes as needed
    }
  }),
  // Define more parent routes with their respective child routes
};

Building routes

Once you have defined your routes, you can build them using the RouteBuildService class:

import {AxiosAdapter} from 'routing-master';
import {RouteBuildService} from 'routing-master';

const axiosAdapter = new AxiosAdapter();
export const routes = new RouteBuildService().buildRoutes(routeDefinerBag, axiosAdapter);

Now you can make requests to your defined routes using the routes object:

const response = await routes.users().edit(1).request();

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.

License

RoutingMaster is open source and released under the MIT License.