Skip to content

Latest commit

 

History

History
214 lines (149 loc) · 4.53 KB

README.md

File metadata and controls

214 lines (149 loc) · 4.53 KB

API Tools

Tools to work with a REST API and WebSocket.

This package allows to:

  • Request specific endpoint with parameters and options.
  • Specify parameters and options within the settings or directly in CLI.
  • Set default parameters and options.
  • Validate parameters and options before a request.
  • Parse API response by filtering, searching and mapping JSON data.
  • Debug signature, request headers, submit data.
  • Analyze API response time, HTTP status and returned code-description.
  • Take snapshots of API response with timestamp to track structure changes.
  • Test API response by validating the structure of an API response against a JSON-schema.

Requirements

Bash ^5.0.0:

$ bash --version
  GNU bash, version 5.1.16(1)-release

Node.js 22.7.0:

$ node -v
  v22.7.0

NPM 10.8.3:

$ npm -v
  10.8.3

Setup

Git

Clone the Git repository:

$ git clone <gh|https|ssh>graycraft/api-tools.git

Node.js

Use appropriate Node.js version:

$ nvm use

NPM

Install modules for usage:

$ npm i --production

Install modules for development:

$ npm i

Environment

Optionally NODE_NO_WARNINGS can be exported from .env file to silence process warnings regarding experimental features.

This command also enables --experimental-vm-modules option for running Jest with ESM:

$ export $(cat .env | xargs)

Settings

Open settings file of an API and set appropriate fields in account, address and authentication sections.

Usage

General syntax of commands:

$ node request|response|socket[ <option>]
$ node <api>[ <handler>[ <parameter>[ <option>]]]

Run all flows for all APIs:

$ node request

Run currency flow for all APIs:

$ node request --flow=currency

<api> is an API name implemented in API Tools:

$ node bybit
$ node coinbase

<handler> is an API request handler:

$ node bybit currencyAll
$ node bybit networkAll

<implicit> is implicit parameter (without value):

$ node bybit currencyAll 10
$ node bybit currencyAll ETHUSDT

<explicit> is explicit parameter (with a value):

$ node bybit currencyAll limit=10
$ node bybit currencyAll pair=ETHUSDT

<option> is option to apply while executing an API request handler or flow:

$ node bybit --flow=order
$ node bybit --verbose
$ node bybit currencyAll  --verbose
$ node bybit currencyAll 10
$ node bybit currencyAll limit=10 --verbose
  • --auth[entication] - output authentication information from internal variables.
  • --debug[ging] - output debugging information from internal variables.
  • --head[ers] - output request and response headers.
  • --verb[ose] - output verbose information about executed request.

Full list of handlers, parameters and options depends on API implementation.

Request

Run flow for all requests of all APIs:

$ node request

To run a flow related to an API request, change directory:

$ cd request

Run flow for all requests of a specific API:

$ node bybit
$ node bybit --flow=orders

Run single request with snapshot (option --snap[shot] is required if not enabled in settings):

$ node bybit currencyAll --snap
$ node bybit currencyAll --snapshot
  Snapped "2024-01-01T00:00:00.000Z.json" to "./snapshot/currency_all".

Response

Run flow for all responses of all APIs (option --aggr[egate] is required if not enabled in settings):

$ node response --aggr
$ node response --aggregate
  Aggregated "2024-01-01T00:00:00.000Z.json" to "../collection/bybit/currency_all".
  Aggregated "2024-01-01T00:00:00.000Z.json" to "../collection/bybit/currency_network_all".
  Aggregated "2024-01-01T00:00:00.000Z.json" to "../collection/coinbase/currency_all".
  Aggregated "2024-01-01T00:00:00.000Z.json" to "../collection/coinbase/currency_network_all".

To run a flow related to an API response, change directory:

$ cd response

Run flow for all responses of a specific API:

$ node bybit
  Aggregated "2024-01-01T00:00:00.000Z.json" to "../collection/bybit/currency_all".
  Aggregated "2024-01-01T00:00:00.000Z.json" to "../collection/bybit/currency_network_all".

Run single response aggregation (option --aggr[egate] is required if not enabled in settings):

$ node bybit currencyAll --aggr
$ node bybit currencyAll --aggregate
  Aggregated "2024-01-01T00:00:00.000Z.json" to "../collection/bybit/currency_all".