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.
Bash ^5.0.0:
$ bash --version
GNU bash, version 5.1.16(1)-releaseNode.js 22.7.0:
$ node -v
v22.7.0NPM 10.8.3:
$ npm -v
10.8.3Clone the Git repository:
$ git clone <gh|https|ssh>graycraft/api-tools.gitUse appropriate Node.js version:
$ nvm useInstall modules for usage:
$ npm i --productionInstall modules for development:
$ npm iOptionally 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)Open settings file of an API and set appropriate fields in account, address and authentication sections.
General syntax of commands:
$ node request|response|socket[ <option>]
$ node <api>[ <handler>[ <parameter>[ <option>]]]Run all flows for all APIs:
$ node requestRun 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.
Run flow for all requests of all APIs:
$ node requestTo run a request flow related to a specific API, change directory:
$ cd requestRun flow for all requests of a specific API:
$ node bybit
$ node coinbaseRun flow for a single request of a specific API:
$ node bybit --flow=orders
$ node coinbase --flow=ordersRun 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".$ node coinbase currencyAll --snap
$ node coinbase currencyAll --snapshot
Snapped "2024-01-01T00:00:00.000Z.json" to "./snapshot/currency_all". aggr: 'aggregate',
auth: 'authentication',
cont: 'continue',
debu: 'debug',
flow: 'flow',
head: 'headers',
snap: 'snapshot',
thro: 'throw',
vali: 'validate',
verb: 'verbose',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".$ node response --vali
$ node response --validate
AJV: validation of Bybit API response snapshot 2025-02-01T23:38:48.058Z.json passed.
AJV: validation of Coinbase API response snapshot 2025-02-10T21:08:43.831Z.json passed.To run a response flow related to a specific API, change directory:
$ cd responseRun flow for all responses of a specific API:
response$ node bybit
response$ node coinbaseRun all response aggregation (option --aggr[egate] is required if not enabled in settings):
response$ node bybit --aggr
response$ node bybit --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".Run all response validation (option --vali[date] is required if not enabled in settings):
response$ node bybit --vali
response$ node bybit --validate
AJV: validation of Bybit API response snapshot 2025-02-01T23:38:48.058Z.json passed.
AJV: validation of Bybit API response snapshot 2025-02-01T23:38:48.532Z.json passed.Run a single response aggregation (option --aggr[egate] is required if not enabled in settings):
response$ node bybit currencyAll --aggr
response$ node bybit currencyAll --aggregate
Aggregated "2024-01-01T00:00:00.000Z.json" to "../collection/bybit/currency_all".Run a single response validation (option --vali[date] is required if not enabled in settings):
response$ node bybit currencyAll --vali
response$ node bybit currencyAll --validate
AJV: validation of Bybit API response snapshot 2025-02-01T23:38:48.058Z.json passed.