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

axios-endpointa

v0.1.5

Published

Axios endpoints helps you to create mor concise endpoint mapping with axios.

Readme

Axios endpoints

Build Status

Axios endpoints helps you to create a more concise endpoint mapping with a simple but flexible api. It is as wrapper over axios.

Getting started

Before anything, install axios-endpoints

npm install --save axios #axios is a peer dependency
npm install --save axios-endpoints

Usage with Factory (recommended)

For a more complete usage of axios settings, you may use the Factory.

import axios from "axios";
import EndpointFactory from "axios-endpoints";

const axiosInstance = axios.create({
    baseURL: "https://localhost:8080/api"
});

const Endpoint = EndpointFactory(axiosInstance);

const cityEndpoint = new Endpoint("/city"); // GET https://localhost:8080/api/city
const postEndpoint = new Endpoint(({id = ""}) => "/post/" + id);

// Header changing example
function setAuthorization(MYTOKEN){
  axiosInstance.defaults.headers.common["Authorization"] = MYTOKEN;
}



function getCityList(callback) {
   cityEndpoint.get().then(response=>{
      callback(response.data);
   }).catch(e=>{
      console.log("That didnt go well");
   });
}

// do you like async stuff? so take this async example
async function getCityList(){
   try{
      const { data } = await cityEndpoint.get();
      return data;
   } catch (e) {
      console.log("That didnt go well");
   }
}

Usage without factory

The fastest way to use axios-endpoints. ideal when you dont want to set any axios configs:

// endpoints.js
import { Endpoint } from "axios-endpoints";

export const userEndpoint = new Endpoint("https://localhost:8080/api/user");


// anotherfile.js
import { userEndpoint } from "./endpoints";

async function getUserList(){
   try{
      const { data } = await userEndpoint.get();
      return data;
   } catch (e) {
      console.log("That didnt go well");
   }
}

HTTP methods

You can user either .get .post .put and .delete as well:


const cityEndpoint = new Endpoint("/city");

const { data } = await cityEndpoint.get(); // GET https://localhost:8080/api/city
const { data } = await cityEndpoint.get({
    params: {country:"brazil"}
}); // GET https://localhost:8080/api/city?country=brazil


const { data } = await cityEndpoint.post({
   name: "Hortolandia", 
   country: "Brazil", 
   hazardLevel: 10000
}, {
  params: { someParam: "icecream" }
}); 
/*
curl --request POST \  
  --url https://localhost:8080/api/city?someParam=icecream \
  --header 'Content-Type: application/json' \
  --data '{
   "name": "Hortolandia", 
   "country": "Brazil", 
   "hazardLevel": 10000
  }'
*/

uriParams

Not always your endpoint will be represented by a fixed string. For that, uri params exists.

const postEndpoint = new Endpoint(({postId = ""}) => "/post/" + postId)

const { data } = await postEndpoint.get({
   uriParams: {
      postId: 1
   }
}); // GET https://localhost:8080/api/post/1

For more information about parameters and returned values, check the API section.

API

EndpointFactory

import axios from "axios";
import EndpointFactory from "axios-endpoints"

const axiosInstance = axios.create(config);
const Enpoint = EndpointFactory(axiosInstance);

Type: function

| Parameters | | |---------------|----------------| | axiosInstance | Axios instance |

axiosInstance is generated via axios.create function. For more information, check axios documentation.

Return: Endpoint

Endpoint

import axios from "axios";
import EndpointFactory from "axios-endpoints"

const axiosInstance = axios.create(config);
const Enpoint = EndpointFactory(axiosInstance);

Type: class

Constructor

| Constructor Parameters | Type | |---------------|----------------| | endpointIdentifier | String or Function any => String |

Instance methods
endpoint#get(options)
endpoint#post(payload, options)
endpoint#put(payload, options)
endpoint#delete(options)

| Parameters | Type | |---------------|----------------| | options | The same object as the Request Config with the extra property | | payload | The object that will be carried as json payload of the request |

You will probably will use params and uriParams more often.

Contributing

If you got so far reading this README, you are maybe thinking about contributing. Pull requests are welcome.