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

reqiox

v1.0.0

Published

Reqiox is a flexible and feature-rich library for making HTTP requests in JavaScript applications. It provides capabilities for request interception, response interception, request cancellation, retry mechanisms, and caching.

Downloads

4

Readme

Reqiox

Reqiox is a flexible and feature-rich library for making HTTP requests in JavaScript applications. It provides capabilities for request interception, response interception, request cancellation, retry mechanisms, and caching.

Features

  • Request Methods: Supports GET, POST, PUT, DELETE methods.
  • Request Interceptors: Customize or transform requests before they are sent.
  • Response Interceptors: Handle and modify responses received from requests.
  • AbortController: Cancel ongoing requests gracefully using AbortController.
  • Retry Mechanism: Automatic retry with exponential backoff for failed requests.
  • Caching: In-memory caching of responses with configurable expiration.

Installation

Install Reqiox via npm:

npm install reqiox --save

import ReqioxClient from 'reqiox';

// Initialize ReqioxClient with base URL
const api = new ReqioxClient('https://api.example.com');

// Add request interceptors (optional)
api.addRequestInterceptor(async (options) => {
  // Modify headers, add authentication tokens, etc.
  return options;
});

// Add response interceptors (optional)
api.addResponseInterceptor(async (response) => {
  // Handle global error responses, transform data, etc.
  return response;
});

// Make GET request
api.get('/posts')
  .then(data => console.log('GET Response:', data))
  .catch(error => console.error('GET Error:', error));

// Make POST request
api.post('/posts', { title: 'New Post', body: 'Content' })
  .then(data => console.log('POST Response:', data))
  .catch(error => console.error('POST Error:', error));

// Cancel a request
api.cancelRequest('/posts', 'GET');

// Clear cache for a specific endpoint
api.clearCache('/posts');

// Retry a request with exponential backoff
api.requestWithRetry('/posts', { method: 'GET' })
  .then(data => console.log('Retry Response:', data))
  .catch(error => console.error('Retry Error:', error));

Library Reference

new ReqioxClient(baseURL)

Creates a new instance of ReqioxClient with the specified base URL.

  • baseURL: Base URL for API requests.

api.addRequestInterceptor(interceptor)

Adds a request interceptor function that will be called before sending a request.

  • interceptor: Function that receives the current request options and returns modified options.

api.addResponseInterceptor(interceptor)

Adds a response interceptor function that will be called when a response is received.

  • interceptor: Function that receives the response object and returns modified response or handles errors.

HTTP Methods

api.get(endpoint, options)

Makes a GET request to the specified endpoint.

  • endpoint: API endpoint.
  • options: Optional request options (e.g., headers, timeout).

api.post(endpoint, body, options)

Makes a POST request to the specified endpoint.

  • endpoint: API endpoint.
  • body: Request body object.
  • options: Optional request options (e.g., headers, timeout).

api.put(endpoint, body, options)

Makes a PUT request to the specified endpoint.

  • endpoint: API endpoint.
  • body: Request body object.
  • options: Optional request options (e.g., headers, timeout).

api.delete(endpoint, options)

Makes a DELETE request to the specified endpoint.

  • endpoint: API endpoint.
  • options: Optional request options (e.g., headers, timeout).

Other Methods

api.cancelRequest(endpoint, method)

Cancels an ongoing request with the specified endpoint and HTTP method.

  • endpoint: API endpoint.
  • method: HTTP method (e.g., GET, POST).

api.clearCache(endpoint)

Clears cached response for the specified endpoint.

  • endpoint: API endpoint.

api.requestWithRetry(endpoint, options, retries)

Retries a failed request with exponential backoff.

  • endpoint: API endpoint.
  • options: Optional request options (e.g., headers, timeout).
  • retries: Optional number of retry attempts (default: 3).