restutils-client
v0.3.5
Published
Generate local client library for the RESTUtils Host
Downloads
5
Maintainers
Readme
RESTUtils Host (restutils-client
)
Generate local client library for APIs created with the RESTUtils Host utility with one command.
Purpose
This package is designed to work exclusively with APIs created using the RESTUtils Host utility. The RESTUtils Host utility works by instantly generating a web-based API from any JavaScript file or Node package. The generated routes can be extensive and they change as your file or package matures. The RESTUtils Client package (this one) connects to your APIs and generates a JavaScript / ES6 client library locally so you don't have to remember the upstream URLs.
Installation
It's best to run from npx
but it can be installed globally...
npm i -g restutils-client
Usage
Generate a new RESTUtils Client in your project with one command...
npx restutils-client --host http://localhost:3000
... and, give it a name if you'd like ...
npx restutils-client --host http://localhost:3000 --name cool-web-api
The best part is you can issue that same one command for all of your upstream APIs...
npx restutils-client --host http://localhost:3001 --name mailboxes \
--host http://localhost:3002 --name processing \
--host http://localhost:3003 --name storage-mobile \
--path ~/apis
From then on, you can simply call your APIs by using simple async functions...
const apis = require('./apis/client');
const main = async () => {
const testData = {
...
};
const result = await apis.storageMobile.messages.storeIncoming(testData);
console.log('result:', result);
}
main();
The --host
parameter is the only required param. That same example above will still work just fine, however the generateing naming becomes a bit generic. So, this...
npx restutils-client --host http://localhost:3001 \
--host http://localhost:3002 \
--host http://localhost:3003
... is used like this:
const apis = require('./restutils/client');
const main = async () => {
const testData = {
...
};
const result = await apis.clientC.messages.storeIncoming(testData);
console.log('result:', result);
}
main();
Environment Variables
To speed up development of your APIs, the URLs provided when you build the client are stored within the generated client.js
file. However, you can easily override these URLs at any time using enviornment variables. They're displayed in the output summary:
RESTUtils Client v0.3.0
FILE : restutils/client.js
HOSTS: 3
CALLS: 4
LINES: 32
Override the upstream URLs using environment variables:
CLIENT_A_BASE=http://localhost:3011
CLIENT_B_BASE=http://localhost:3012
CLIENT_C_BASE=http://localhost:3013
Have a great day!
Parameters
| Name | Description | Type | Default |
|--------|-----------------------|-----------------|---------|
| host
| URL to the API | string
| |
| name
| Names of the API | string
| |
| path
| Path to client folder | string (path)
| |
Contact
Please feel free to contact me directly with any questions, comments, or enhancement requests:
Fred Lackey
[email protected]
http://fredlackey.com