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

Usage no npm install needed!

<script type="module">
  import aidaInjectorRoutesMap from 'https://cdn.skypack.dev/@aida/injector-routes-map';


Injector - Routes Map


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.


The Routes Map injector depends on:

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.


//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



This injector doesn't take any own options.