Engineering

⌘K
  1. Home
  2. Docs
  3. Engineering
  4. REST API Client and OpenAPI

REST API Client and OpenAPI

Lovia Group generally prefers GraphQL for synchronous remote APIs. However, third-party software may expose REST API. Some of them are kind enough to provide a language-specific SDK, which is preferred whenever possible. Some provide OpenAPI that you can use to generate client SDK for any language using OpenAPI Generator.

Using OpenAPI from TypeScript-Axios Projects

For Node.js or React platform, we prefer TypeScript language with Axios as HTTP library. First, install OpenAPI Generator globally.

yarn global add @openapitools/openapi-generator-cli

Example: To generate TypeScript Client from Camunda OpenAPI:

openapi-generator generate -g typescript-axios --additional-properties=modelPropertyNaming=original --additional-properties=supportsES6=true -o out -i https://start.camunda.com/openapi.json

If using regular Node.js project, you can put that into package.json:

"scripts": {
  ...
  "openapi:camunda": "openapi-generator generate -g typescript-axios --additional-properties=modelPropertyNaming=original --additional-properties=supportsES6=true -o out -i https://start.camunda.com/openapi.json",
  ...
}

Then you can generate by:

yarn openapi:camunda

If you use Nx monorepo build system, put Nx custom command into workspace.json to generate for a single project:

  "projects": {
    "miluv-profile": {
      ...
      "targets": {
        "openapi-camunda": {
          "executor": "@nrwl/workspace:run-commands",
          "options": {
            "commands": [
              {
                "command": "$HOME/.yarn/bin/openapi-generator-cli generate -g typescript-axios --additional-properties=modelPropertyNaming=original --additional-properties=supportsES6=true -o out -i https://start.camunda.com/openapi.json"
              }
            ]
          }
        }
      }

Then run it with:

yarn nx run miluv-profile:openapi-camunda

With Nx, you should not put this inside an app, but rather in its own library in libs.

Create a library:

yarn nx g @nrwl/nest:lib camunda-client
  "projects": {
    "camunda-client": {
      ...
      "targets": {
        "generate": {
          "executor": "@nrwl/workspace:run-commands",
          "options": {
            "commands": [
              {
                "command": "$HOME/.yarn/bin/openapi-generator-cli generate -g typescript-axios --additional-properties=modelPropertyNaming=original --additional-properties=supportsES6=true -o libs/camunda-client/src -i https://start.camunda.com/openapi.json"
              }
            ]
          }
        }
      }

Then run it with:

yarn nx run camunda-client:generate

Postman

To experiment with REST API (and also GraphQL), we use Postman.

Install in Ubuntu:

sudo snap install postman

Please sign up for Postman account so your collections and requests are synchronized with Postman Cloud.

Note: Postman in Snap repository may lag behind a bit when a new major version is freshly released, but it’s easier to install and it will auto-update anyway when the new major version is more stable.

How can we help?