New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aida/injector-routes-map

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aida/injector-routes-map

Aida injector to create a map of all operation ids and their accompanying routes

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by14.29%
Maintainers
1
Weekly downloads
 
Created
Source

Injector - Routes Map

Introduction

The Routes Map injector generates a hash map of the operation ID of an endpoint, and the URL for that endpoint (including template placeholders). Note that each endpoint definition must have a unique operationId property for each route, otherwise there will be routes missing from the resulting map.

Dependencies

The Routes Map injector depends on:

  • @aida/injector-routes

Use Cases

The main use case for this injector is to generate a file with all defined routes which can be accessed by ID. Using such an approach makes it trivial to make changes to the URL without making any changes to your code that uses the routes map.

Example

//This is what is generated from the injector
const routesMap = {
  'getUser': '/users/{id}',
  'updateUser': '/users/{id}',
}

//Replaces template placeholders with a concrete value.
function getRoute(routeName, params) {
  const routeTemplate = routesMap[routeName];
  if (!params) {
    return routeTemplate;
  }

  return Object.keys(params).reduce((parsedPath, paramName) => {
    return routeTemplate.replace(`{${paramName}}`, params[paramName]);
  }, '');
}

fetch(getRoute('getUser')) //Make and request as usual

API

options

This injector doesn't take any own options.

FAQs

Package last updated on 17 Jun 2019

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