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

api-easy-request

v1.0.1

Published

A simple and flexible API request library with built-in features

Readme

api-easy-request

A simple and flexible API request library with built-in features.

Installation

npm install api-easy-request

Features

  • Simple and intuitive API
  • TypeScript support
  • Global configuration
  • Request/Response interceptors
  • Timeout handling
  • Automatic JSON parsing
  • Support for different body types (JSON, FormData, Text)
  • Query parameters support
  • Error handling with detailed information

Usage

Basic Usage

import { get, post, put, del } from 'api-easy-request';

// GET request
const response = await get('https://api.example.com/users');
console.log(response.data);

// POST request
const newUser = await post('https://api.example.com/users', {
  name: 'John',
  email: '[email protected]'
});

// PUT request
const updatedUser = await put('https://api.example.com/users/1', {
  name: 'John Updated'
});

// DELETE request
const deleted = await del('https://api.example.com/users/1');

Global Configuration

import { setGlobalOptions } from 'api-easy-request';

setGlobalOptions({
  baseUrl: 'https://api.example.com',
  headers: {
    'Authorization': 'Bearer token'
  },
  timeout: 5000
});

// Now all requests will use the baseUrl
const users = await get('/users');

Using Interceptors

import { setInterceptors } from 'api-easy-request';

setInterceptors({
  request: async (config) => {
    // Add auth token to all requests
    config.headers['Authorization'] = 'Bearer token';
    return config;
  },
  response: async (response) => {
    // Log all responses
    console.log('Response:', response);
    return response;
  }
});

Error Handling

try {
  const response = await get('https://api.example.com/users');
} catch (error) {
  if (error.status === 404) {
    console.log('Resource not found');
  } else {
    console.error('Error:', error.message);
    console.error('Status:', error.status);
    console.error('Body:', error.body);
  }
}

Advanced Options

// GET with query parameters
const response = await get('/users', {
  params: {
    page: 1,
    limit: 10
  }
});

// POST with FormData
const formResponse = await post('/upload', formData, {
  bodyType: 'form'
});

// Custom timeout
const response = await get('/users', {
  timeout: 10000 // 10 seconds
});

// Custom headers
const response = await get('/users', {
  headers: {
    'X-Custom-Header': 'value'
  }
});

API Reference

Methods

  • get<T>(url: string, options?: RequestOptions): Promise<ApiResponse<T>>
  • post<T>(url: string, data?: any, options?: RequestOptions): Promise<ApiResponse<T>>
  • put<T>(url: string, data?: any, options?: RequestOptions): Promise<ApiResponse<T>>
  • del<T>(url: string, options?: RequestOptions): Promise<ApiResponse<T>>
  • patch<T>(url: string, data?: any, options?: RequestOptions): Promise<ApiResponse<T>>
  • setGlobalOptions(options: GlobalOptions): void
  • setInterceptors(interceptors: Interceptors): void

Types

interface RequestOptions {
  headers?: Record<string, string>;
  params?: Record<string, string | number | boolean>;
  timeout?: number;
  bodyType?: 'json' | 'form' | 'text';
  signal?: AbortSignal;
}

interface GlobalOptions extends RequestOptions {
  baseUrl?: string;
}

interface Interceptors {
  request?: (config: RequestInit) => RequestInit | Promise<RequestInit>;
  response?: (response: Response) => Response | Promise<Response>;
}

interface ApiResponse<T = any> {
  data: T;
  status: number;
  headers: Headers;
}

License

MIT