parallel-api-calls
v0.0.2
Published
To use ParallelApiCalls as an NPM package, install it by running:
Downloads
3
Readme
Usage
To use ParallelApiCalls as an NPM package, install it by running:
npm install parallel-api-calls
Import the ParallelApiCalls class and the required dependencies:
import ParallelApiCalls from 'parallel-api-calls';
import ApiEndpoint, { ApiEndpointResponse } from "./ApiEndpoint";
Create an instance of ParallelApiCalls by passing an array of ApiEndpoint instances to the constructor:
const apiEndpoints = [/* ... */];
const parallelApiCalls = new ParallelApiCalls(apiEndpoints);
Execute parallel API calls and retrieve the transformed data:
try {
const transformedData = await parallelApiCalls.run();
console.log('Transformed data:', transformedData);
} catch (error) {
console.error('Error:', error);
}
Methods
run(force: boolean = false): Promise<ApiEndpointResponse[]>
Makes multiple API requests, transforms the responses, and returns the transformed data.
Parameters: force (optional): If set to true, forces a fresh API call even if results are cached. Returns: A Promise that resolves to an array of type ApiEndpointResponse[]. getOnlyResultsData(): any[]
Retrieves only the data from the transformed results.
Returns: An array containing the transformed data.
getResults(): ApiEndpointResponse[]
Retrieves the raw results, including both data and metadata.
Returns: An array of type ApiEndpointResponse[]. Example
const apiEndpoints = [/* ... */];
const parallelApiCalls = new ParallelApiCalls(apiEndpoints);
try {
const transformedData = await parallelApiCalls.run();
console.log('Transformed data:', transformedData);
} catch (error) {
console.error('Error:', error);
}
Developemnt
Use the devcontainer to develop the project. The devcontainer is a docker container with all the tools needed to develop the project. It also contains the project dependencies.
To start the devcontainer, open the command palette and select Remote-Containers: Reopen in Container
.
Use yarn
to install dependencies.