Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reqiox

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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.

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

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).

Keywords

FAQs

Package last updated on 06 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc