@hexarc/api-generator
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

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-generator

Or globally:

npm install -g @hexarc/api-generator

During 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 --help

Or 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 just Api

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 classes
  • controllers - concrete API controller classes
  • types - all types used by the API controllers
  • values - common values used between client and server applications (like errors and etc.)
  • api.ts - file with the api client class

Readme

Keywords

none

Package Sidebar

Install

npm i @hexarc/api-generator

Weekly Downloads

1

Version

1.4.0

License

MIT

Unpacked Size

94.1 kB

Total Files

102

Last publish

Collaborators

  • shadeglare