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

@gwansikk/query-fetch

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gwansikk/query-fetch

Lightweight and Easy-to-Use Fetch API Extension Library

  • 0.7.3
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

🔗 Query Fetch

Lightweight and Easy-to-Use Fetch API Extension Library.

npm version npm downloads npm bundle size

English   •   한국어

What is Query Fetch?

The Fetch API often lacks necessary features, requiring direct implementation. You have to handle retries on failure, token renewal, request and response logging, request cancellation, and more on your own. Additionally, you often need to repeat the same configurations for every request.

Moreover, dealing with Promise objects can be quite challenging. Using Promises for asynchronous processing can lead to complex structures and difficult error handling. Managing multiple asynchronous requests sequentially or in parallel can reduce code readability and maintainability.

To address these issues, Query Fetch was created. It alleviates the burden of network communication, allowing you to focus on your core logic!

Features

  • Instance Management: Query Fetch allows you to create multiple instances, each with different settings. This makes it easy to manage integrations with various API endpoints or services.
  • Automatic Retries: Automatically retries requests in case of network errors or server issues.
  • Request Cancellation: Provides the ability to cancel unnecessary requests.
  • Token Management: Automatically refreshes authentication tokens when they expire and retries the request.
  • Type Safe: Fully supports TypeScript, ensuring accurate type inference and minimizing unnecessary types.

Installation

Query Fetch is available on npm. You can install it using the following commands.

npm i @gwansikk/query-fetch
pnpm add @gwansikk/query-fetch
yarn add @gwansikk/query-fetch

Usage

[!IMPORTANT]
Query Fetch is currently in development. The provided API is subject to change.

Instance

const queryFetch = createQueryFetch({
  baseURL: 'https://jsonplaceholder.typicode.com',
});

queryFetch.get({ endpoint: ['posts', 1] }).then((data) => console.log(data));

Interceptor

const queryFetch = createQueryFetch({
  baseURL: 'https://jsonplaceholder.typicode.com',
  interceptors: {
    request: (request) => {
      console.log('** request interceptor **');
      // Modify and return the request.
      // For example, you can add specific headers or modify the URL.
      request.headers = {
        ...request.headers,
        Authorization: 'Bearer YOUR_ACCESS_TOKEN',
      };
      return request;
    },
    response: (response) => {
      console.log('** response interceptor **');
      // Modify and return the response.
      return response;
    },
    error: (response) => {
      console.log('** error interceptor **');
      // Modify and return the error response.
      return response;
    },
  },
});

queryFetch.get({ endpoint: ['posts', 1] }).then((data) => console.log(data));

Roadmap

Here is the roadmap for the official release (v1.0.0).

  • Automatic JSON conversion
  • Instance creation
  • Request and response interceptors
  • Query Parameter
  • Automatic retries
  • Error status handling
  • Request cancellation
  • Token management

Contributing

We welcome contribution from everyone in the community. Read below for detailed contribution guide.

CONTRIBUTING.md

Contributors

contributors

License

For more details, please refer to the LICENSE.

MIT © gwansikk

Keywords

FAQs

Package last updated on 15 Aug 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