Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

route-repository

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

route-repository

Framework agnostic storage of front to back routing information.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

route-repository

A simple front to back router package for JavaScript. Useful when your front-end has to send request to back-end APIs.

What this package provides:

  • A javascript way of storing and accessing your route aliases, URIs and their associated HTTP methods.

What this package does not provide:

  • An ajax client. You can use another package like axios with this package.
  • A front-end virtual DOM router like react router, although again, you can totally use this package with a virtual DOM router. The use cases are not overlapping but complementary.

Why?

In short, you get access to the following features and benefits:

  • A layer of abstraction makes it easy to replace and reuse routes
  • Reduces the headache of refactoring when URIs or HTTP methods change
  • No more hardcoded URI strings
  • Dynamically register routes
  • Supports URI parameter binding (for example: /users/{id})
  • Routes keep track of the correct HTTP method (verb), making ajax calls more dynamic
  • List all registered routes for easy debugging
  • You can easily swap the base URIs of your entire application, which makes development and using proxies very convenient. Simply enable cross-origin request and point the base URI of your application to a mock backend

Installation

NPM

Install package:

npm install route-repository

Import the main class:

import { RouteRepository } from 'route-repository';
var repository = new RouteRepository();
Browser

Include directly from one of the public CDN providers:

<script src="https://jsdelivr.com/route-repository/dist/route-repository.min.js"></script>
<script src="https://unpkg.com/-modernized/dist/route-repository.min.js"></script>

Use the route_repository window object to access classes under the package namespace:

const library = route_repository
var repository = new library.RouteRepository()

Basic usage

Register a new route:

// route name, HTTP method, uri
repository.register('user.show', 'GET', '/backend/users/{id}');

// or
repository.get('user.show', '/backend/users/{id}');

Get the registered route:

var route = repository.getRoute('user.index');

Example usage with axios:

repository.registerAll([{
    name: 'user.show',
    method: 'GET',
    uri: '/backend/users/{id}'
}]);

var route = repository.getRoute('user.index');

// Bind the userId as uri parameter, the resulting uri will be /backend/users/1
var userId = 1;

// Send the request
axios({
  method: route.method(),
  url: route.uri.bindParameters(userId)
});

Documentation

Check out the documentation for all methods and public API provided by this package.

It is also highly recommended to take a look at the server side integration to understand the optimal workflow and how to get the most out of using this package.

Changes

See the changelog for notes on changes introduced in different package versions (since 2.0.0)

Keywords

FAQs

Package last updated on 22 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc