0.3.5 • Published 10 months ago

restutils-client v0.3.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
10 months ago

RESTUtils Logo

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

NameDescriptionTypeDefault
hostURL to the APIstring
nameNames of the APIstring
pathPath to client folderstring (path)

Contact

Please feel free to contact me directly with any questions, comments, or enhancement requests:

Fred Lackey
fred.lackey@gmail.com
http://fredlackey.com

0.3.5

10 months ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago

0.0.0

2 years ago