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 🙏

© 2024 – Pkg Stats / Ryan Hefner

ianes

v0.1.1

Published

A request handler based on axios

Downloads

3

Readme

Ianes

Ianes - A request handler based on axios

npm version Statements coverage

IANES is a wrapper for axios, a promise based HTTP client for the browser and node.js. Built with :heart:.

Features

  • Easy configuration for global Authorization Header
  • Easy connfiguration for global apiUrl
  • Supports the Promise API
  • Intercept request and response
  • Transform request and response data

Installing

Using yarn:

$ yarn add ianes

Using npm:

$ npm install ianes

Getting Started

If your're using React, we recommend you to configure IANES in some of the entry point of your application. In our example, it was made in the file that contains all the possible routes.

//others imports
import { configureIanes } from "ianes/modules";

const API_URL = "http://localhost:3000/api";
const DEFAULT_CONTENT_TYPE = "application/json";
const DEFAULT_TIMEOUT = 240000;

const configurations = {
  apiUrl: API_URL,
  defaultContentType: DEFAULT_CONTENT_TYPE,
  defaultTimeout: DEFAULT_TIMEOUT,
};

configureIanes(configurations);
//more code...

Configurations

By default,handleResponseDataSuccess and handleResponseError are initialized with default handlers functions. Also, defaultContentType and defaultTimeout are initialized with application/json and 240000, respectively.

The configureIanes method accept the following properties:

{
  //default base url used in requests
  apiUrl: "https://myapiurl.com",
  
  //It will be used in the Authorization header in all requests sent
  apiToken: "Bearer MYWEBTOKENAPIANDANOTHERSWORDS",
  
  //Content type to be used in requests sent
  defaultContentType: "application/json",
  
  //defaultTimeout should be a number
  defaultTimeout: 240000,
  
  //handleBeforeTheRequestIsSent expects a function that should return the config object
  handleBeforeTheRequestIsSent: config => config,
  
  //handleRequestError expects a function that must return a promise
  handleRequestError: error => Promise.reject(error),
  
  //handleResponseDataSuccess expects a function that should return response
  handleResponseDataSuccess: response => (response),
  
  //handleRequestError expects a function that must return a promise with the error object
  handleResponseError: error => Promise.reject(error)
}

Examples

Set Authorization Header

Setting token through setAuthorizationHeader makes that Authorization header sent in requests uses the value passed by it.

import { setAuthorizationHeader } from "ianes/modules";

const token = "Bearer MYWEBTOKENAPIANDANOTHERSWORDS"
setAuthorizationHeader(token);

Reset Authorization Header

Resetting token through resetAuthorizationHeader makes that Authorization header stops being sent.

import { resetAuthorizationHeader } from "ianes/modules";

resetAuthorizationHeader();

Get

import { get } from "ianes/modules";

get("/teachers")
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.log(error)
  })

Post

import { post } from "ianes/modules";

const student = { name: "John Mayer", age: 21 };

post("/students", student)
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.log(error)
  })

Put

import { put } from "ianes/modules";

const student = { id: 234432, name: "Marrie Mayer", age: 21 };

put(`/students/${student.id}`, student)
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.log(error)
  })

Patch

import { patch } from "ianes/modules";

const student = { id: 234432, name: "Marrie Mayer", age: 21 };

patch(`/students/${student.id}`, { name: "Larry" })
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.log(error)
  })

Remove (delete)

import { patch } from "ianes/modules";

const student = { id: 234432, name: "Marrie Mayer", age: 21 };

patch(`/students/${student.id}`)
  .then((response) => {
    console.log(response)
  })
  .catch((error) => {
    console.log(error)
  })

Credits

Ianes is heavily based on axios.