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

easy-api-consumer

v1.2.5

Published

A modern Node.js library to facilitate HTTP requests, authentication, and API creation in a simple, organized, and reusable way.

Readme

Easy API Consumer - A Node.js library for simplified HTTP requests, authentication, and API communication.

Repositório oficial: https://github.com/open-ylorde/easy-api-consumer


Resources

  • HTTP Client — Simplified interface for making GET, POST, PUT, PATCH and DELETE requests.
  • Authentication — Built-in authentication token management with helpers to get, set and clear tokens.
  • Authenticated Requests — Easily enable or disable authentication on individual requests.
  • Device Information — Utilities for detecting the device type and retrieving the client's IP address.
  • Flexible Configuration — Configure a base API URL and customize request behavior according to your application's needs.
  • Reusable API Layer — Organize and reuse API endpoints without repeating request configuration.
  • TypeScript Support — Fully typed API interface for a better development experience.
  • Lightweight & Simple — Designed to provide the features you need without unnecessary complexity.
  • Centralized API Management — Keep authentication, API configuration and request handling in one place.

Installation

npm install easy-api-consumer

Example Usage

1. Define your request interfaces

Create interfaces for the authentication payloads:

// @/interfaces/ILogin.ts

export interface ILoginBody {
  email: string;
  password: string;
}

export interface IRegisterBody {
  username: string;
  email: string;
  password: string;
}

2. Configure the API client

Initialize EasyAPIConsumer with your API's base URL and expose the utilities you need throughout your application:

// @/lib/api.ts

import { EasyAPIConsumer } from "easy-api-consumer";

const easyApi = new EasyAPIConsumer({
  baseURL: "https://api.site.com",
});

const { api, noAuth, utils, token } = easyApi;

const { getDeviceType, getDeviceIpAddress } = utils;

const {
  getAuthToken,
  setAuthToken,
  clearAuthToken,
} = token;

export {
  api,
  noAuth,
  getAuthToken,
  setAuthToken,
  clearAuthToken,
  getDeviceType,
  getDeviceIpAddress,
};

EasyAPIConsumer handles the API configuration, authentication token management, and device information utilities for you.


3. Create your API endpoints

You can organize your endpoints by feature. For example, authentication-related requests can be grouped into an authApi object:

// @/lib/endpoints/auth.ts

import { api } from "../api";
import {
  ILoginBody,
  IRegisterBody,
} from "@/interfaces/ILogin";

export const authApi = {
  login: (body: ILoginBody) =>
    api.post(
      "/auth/login",
      body,
      {
        includesDeviceIpAddress: true,
        includesDeviceType: true,
        auth: false,
      }
    ),

  register: (body: IRegisterBody) =>
    api.post(
      "/auth/register",
      body,
      {
        auth: false,
      }
    ),

  me: () =>
    api.get(
      "/auth/me",
      {
        includesDeviceIpAddress: true,
      }
    ),

  logout: () =>
    api.post(
      "/auth/logout",
      {
        includesDeviceIpAddress: true,
      }
    ),
};

4. Using the endpoints

Once the endpoints are defined, requests can be made directly from your application:

import { authApi } from "@/lib/endpoints/auth";

const login = async () => {
  const response = await authApi.login({
    email: "[email protected]",
    password: "password",
  });

  console.log(response);
};

This approach keeps the API layer organized and makes it easier to maintain and scale as your application grows.


includesDeviceIpAddress?: boolean

Whether to include the client's IPv4 address in the request headers. When enabled, the IP address is sent through the Device-Ip-Address header.


includesDeviceType?: boolean

An optional boolean setting that determines whether the client's device type should be included in the request headers.

When enabled, the device type is added to the Device-Type header. The value is an array containing one or more of the following device types:

  • android
  • ios
  • windows
  • macos
  • linux
  • unknown

The supported device types are defined by the DeviceType type.

export type DeviceType = "android" | "ios" | "windows" | "macos" | "linux" | "unknown";

License

This project is licensed under the GPL-3.0 License.

Credits

The implementation of request.ts was based on code originally created by SorPuti.

The code was adapted for this project.

The original code did not specify a usage license. This credit is provided as attribution to the original author.

Author

Copyright (c) 2026 Davi de Sousa