fluke-api-generator v2.1.0
Fluke API generator
This NPM package provides ability to generate a Fluke API client for frontend TypeScript/Javascript projects from the API schema that can be obtain from one of the Fluke API services.
Setup
The package can be installed using the npm package manager in a TypeScript/JavaScript frontend project:
npm install --save-dev fluke-api-generatorOr globally:
npm install -g @fluke-api-generatorDuring installation the package will register a CLI-utility for API client generation.
Be advised that this package is developed and tested under Unix-like environment. Not tested on Win platforms.
Generation
As mentioned the package provides the CLI-utility to build an API client for any Fluke API that supports API schema exposing via a special endpoint. The CLI-utility can be call via shell:
npx fluke --helpOr if installed globally:
fluke --help--help option will show available options for generation.
A common command to generate an API client:
npx fluke <api_schema_url> <output_dir>Arguments:
<api_schema_url>- an API services endpoint that expose the API schema,<output_dir>- the output directory for a generated API client.
Options:
--api-client-name <name>- an API client class name. Default name is justApi
Usage
A generated API client will be located in the provided output directory.
Now you can import and use the generated API client class into any project file:
import { Api } from "./output_dir"
const api = new Api("https://example.com");
...
await api.controllerName.controllerMethod(arg1, arg2);Api structure
Every generated API client has a common structure that can be explored:
bootstrap- directory for some base classescontrollers- concrete API controller classestypes- all types used by the API controllersvalues- common values used between client and server applications (like errors and etc.)api.ts- file with the api client class