@hexarc/api-generator v1.4.0
Hexarc API generator for Typescript/Javascript project
This NPM package provides ability to generate a Hexarc API client for frontend TypeScript/Javascript projects from the API schema that can be obtain from one of the Hexarc API services.
Setup
The package can be installed using the npm package manager in a TypeScript/JavaScript frontend project:
npm install --save-dev @hexarc/api-generatorOr globally:
npm install -g @hexarc/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 Hexarc API that supports API schema exposing via a special endpoint. The CLI-utility can be call via shell:
npx hexarc --helpOr if installed globally:
hexarc --help--help option will show available options for generation.
A common command to generate an API client:
npx hexarc <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