0.1.3 • Published 8 months ago

@kifpool/advanced-api-sdk v0.1.3

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
8 months ago

Kifpool Advanced API SDK

Introduction

The @kifpool/advanced-api-sdk is a powerful and flexible SDK for interacting with Kifpool Advanced API. It provides a functional programming approach to interacting with APIs while supporting features such as request simulation, encryption, and logging.

Installation

npm install @kifpool/advanced-api-sdk

or using Yarn:

yarn add @kifpool/advanced-api-sdk

Usage

Importing the SDK

import api from '@kifpool/advanced-api-sdk';

Creating a Connection

To interact with an API, you need to set up a connection using the IConnection interface.

const connection: api.IConnection = {
    host: 'https://something.com',
    simulate: true,
};

Making API Requests

Fetching Fear and Greed Index

api.functional.fear_and_greed.index(connection).then((response) => {
    console.log(response);
});

Fetching Token List with Pagination

async function getTokens() {
    const response = await api.functional.token.index(connection, {page: 1, limit: 10});
    console.log(response);
}

getTokens();

IConnection Interface

The IConnection interface allows you to define the connection settings for the SDK. Below are the available options:

Properties

  • host (string) - The remote HTTP server's host address.
  • headers (object) - Optional custom headers for API requests.
  • simulate (boolean | Partial<IRandomGenerator>) - Enables simulation mode where requests return mock data instead of hitting the API.
  • logger ((event: IFetchEvent) => Promise<void>) - A callback function triggered after fetch events.
  • encryption (IEncryptionPassword | IEncryptionPassword.Closure) - Configures AES-128/256 encryption for secure communication.
  • options (IConnection.IOptions) - Additional options for the fetch function.
  • fetch (typeof fetch) - Custom fetch function, useful for Node.js environments without built-in fetch.

Fetch Options (IConnection.IOptions)

These options allow additional configurations for fetch requests:

  • cache ("default" | "force-cache" | "no-cache" | "no-store" | "only-if-cached" | "reload") - Determines how the request interacts with the cache.
  • credentials ("omit" | "same-origin" | "include") - Defines how credentials are sent with requests.
  • integrity (string) - Cryptographic hash of the resource.
  • keepalive (boolean) - Enables or disables keepalive mode.
  • mode ("cors" | "navigate" | "no-cors" | "same-origin") - Defines CORS behavior.
  • redirect ("error" | "follow" | "manual") - Determines how redirects are handled.
  • referrer (string) - The referrer URL.
  • referrerPolicy ("no-referrer" | "origin" | "same-origin" | ...) - Defines referrer behavior.
  • signal (AbortSignal | null) - Allows request cancellation.
0.1.3

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago