1.0.893 • Published 5 months ago

ak-fetch v1.0.893

Weekly downloads
-
License
ISC
Repository
github
Last release
5 months ago

ak-fetch

tldr;

a "batch and queue" HTTP client for making bulk POST requests to an API endpoint:

🌍 Overview

ak-fetch is a powerful and flexible tool designed for making bulk POST requests to an API endpoint. It provides a simple interface to batch and queue requests which send data over the network; it adds oft needed features like concurrency control, retries, fire-and-forget making it a robust solution for handling large data transfer operations with ease.

i built this module when creating hello-mixpanel as i needed a way to send large amounts of data to various SaaS analytics APIs in a reliable and efficient manner. it was useful enough for me, that i made it into a proper package.

🚀 Installation

To get started with ak-fetch, install the module using npm:

npm install ak-fetch

you may also use npx to run the CLI without installing the package:

npx ak-fetch --help

🖥️ Usage

Use ak-fetch as a module directly in your node script:

const akFetch = require('ak-fetch');
const config = {
        url: 'https://api.example.com',
        data: [...],
		batchSize: 10,
		concurrency: 5,
		delay: 1000,
        // ... other configurations
};

try {
	const responses = await akFetch(config);
	console.log('API Responses:', responses);
} catch (error) {
	console.error('Error:', error);
}

or via the command line:

npx ak-fetch --url https://api.example.com './payloads.json' --batchSize 10 --concurrency 5

Use --help to see all options

🛠️ Configuration

The ak-fetch module can be configured with a variety of options to suit your needs:

OptionTypeDescription
urlstringThe URL of the API endpoint.
dataObject[]An array of data objects to be sent in the requests.
batchSizenumber# records per batch; Use 0 for no batching.
concurrencynumberThe level of concurrency for the requests.
delaynumberThe delay between requests in milliseconds.
searchParamsObjectThe search parameters to be appended to the URL.
bodyParamsObjectThe body parameters to be sent in the request.
headersObjectThe headers to be sent in the request.
verbosebooleanWhether to log progress of the requests.
dryRunbooleanIf true, no actual requests are made.
logFilestringFile path where responses will be saved.
retriesnumberNumber of retries for failed requests; use null for fire-and-forget.
retryDelaynumberDelay between retries in milliseconds.
retryOnnumber[]HTTP status codes to retry on.

(note that with the CLI you may use camelCase or snake_case for options)

🧩 Contributing

Contributions to ak-fetch are welcome! Feel free to open issues or submit pull requests.

📝 License

ak-fetch is ISC licensed; use it however you wish.

1.0.893

5 months ago

1.0.892

7 months ago

1.0.891

7 months ago

1.0.88

7 months ago

1.0.89

7 months ago

1.0.84

7 months ago

1.0.87

7 months ago

1.0.86

7 months ago

1.0.85

7 months ago

1.0.8

8 months ago

1.0.83

7 months ago

1.0.82

7 months ago

1.0.81

7 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

10 months ago

1.0.19

11 months ago

1.0.18

11 months ago

1.0.17

11 months ago

1.0.16

12 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.21

11 months ago

1.0.20

11 months ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago