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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wallrio/apimapper

v1.1.2

Published

API mapper, for centralizing requests.

Readme

APIMapper

This project aims to facilitate communication with external services via HTTP requests. The idea is to map all external services used in the application and have an internal API Gateway to abstract and centralize the calls.

Installation

npm install @wallrio/apimapper

Configuration

First, the configuration file is created, where endpoints and request parameters are defined.

The configuration file is a JSON file with the following structure:

{
    "environment":"prod",
    "workspace":{
        "id":"id-workspace",
        "title":"Title Workspace",
        "description":"Description of workspace"     
    },
    "global":{
        "headers":{
            "Content-Type": "application/json"
        },
        "vars":{
            "author-site":"wallrio.com"
        }
    },
    "vars":{        
        "prod":{
            "accounts": "https://api.{:domain}/accounts",             
            "payment": "https://api.{:domain}/payment"          
        },
        "hmlg":{
            "accounts": "http://localhost:8001",    
            "payment": "http://localhost:8002"                                
        }
    },
    "requests":{

        "accounts/users":{
            "method":"get",
            "path":"{vars:accounts}/users/{:id}?domain={:domain}",
            "headers":{
                "custom_header": "{global.vars:author-site}"
            },
            "description":"this endpoint returns the data of a user"
        }
                  
    },
    "folders":{    
        "accounts/users":{      
            "title":"Users",
            "parent":"accounts"
        },
        "accounts":{      
            "title":"Accounts",
            "parent":"/"
        }
    }    
}

| Parametro | Descrição | Uso | |:-----|:-----|:-----| | environment | Defines which environment will be used.| Optional | | workspace | Defines which workspace will be used.| Optional | | global | Defines parameters that can be used in all environments. | Optional | | vars | Defines environment-based variables that will be used in endpoints. | Optional | | requests | Defines the endpoints that will be used. | | | folders | Defines categories where requests will be grouped. | Optional |

Minimum parameters the configuration file should have:

{    
    "requests":{
        "accounts/users":{
            "method":"get",
            "path":"https://api.{:domain}/accounts/users/{:id}?domain={:domain}",            
        }                  
    }    
}

Usage

Initially, two usage modes were envisioned:

- Node
- ContextAPI

Node Mode

In this mode, the library is used individually.

import APIMapper from '@wallrio/apimapper';
import APIMapperConfig from "@root/../apimapper.routes.json";

// here the configuration file to be used is defined.
const API = new APIMapper(APIMapperConfig);

/* 
here the request is made.
the HTTP method parameters are defined in the configuration file.
*/
let responseRequest = await API.request('accounts/users',{						
    "params":{        
        "userid":"1234567890"
    }
});


Other parameters are allowed:

- params: used for replacing in the endpoint of the request.
- headers: optional, can be defined in the configuration file.
- body: optional.

Example:

let responseRequest = await API.request('accounts/users',{						
    "params":{        
        "userid":"1234567890"
    },
    "headers":{
        "Content-Type": "application/json"
    }
    "body":{
        "name":"Fulano da Silva",
        "username":"fulano"
    }
});

Options

let responseRequest = await API.request('accounts/users',{						   
    "options":{
        "verbose": true
    }
});

Midleware

It is useful for adding functionality before making the request, and possibly altering some parameters before sending.

If the middleware returns a false promise, the request is aborted.

Example: file @root/src/middleware/APIMapper.middleware.ts

export const middlewareTest = async (path:string, params:Record<string, any>) => {
    console.log(path, params,'test...');
    params.headers['Content-Type'] = 'application/json';
    params.test = 123;
    
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            // resolve(new Error('Mocked ok')); // the request will be made
            reject(new Error('Mocked rejection')); // the request is aborted
        }, 5000);
    });
}

To add the middleware:

import {middlewareTest} from "@root/src/middleware/APIMapper.middleware"
API.addMiddleware(middlewareTest);

ContextAPI Mode

In this mode, the library is used integrated with a ContextAPI, and the library will be available throughout the application.

Here’s a complete example of how to use it.

Step 1

Create the provider.

  • file @root/src/app/context/ProxyProvider.tsx
'use client';
import { createContext} from "react";
export const ProxyContext = createContext({});

import APIMapper from '@wallrio/apimapper';
import APIMapperConfig from "@root/../APIMapper.routes.json";

export function ProxyProvider({ children }) {

    const API = new APIMapper(APIMapperConfig);
       
    return (
        <ProxyContext.Provider value={{ authenticated: true,         
            API:API
        }}>	          
          {children}		
        </ProxyContext.Provider>
    );
}        

Step 2

Create the application.

  • Application
<ProxyProvider> 
    <Componente>
        {children}
    </Componente>
</ProxyProvider>     

Step 3

Create the component where the HTTP call will be made.

  • Component
import { useContext } from "react";
import { ProxyContext } from "./Proxy";
export default function Componente({children}){
    const {API} = useContext(ProxyContext);

    let responseRequest = await API.request('accounts/users',{						
        "params":{        
            "userid":"1234567890"
        }
    });
}