Generating API Clients for Usage

OpenAPI Client

In the context of OpenAPI, a "client code" refers to the base code that facilitates interaction with an API from the client's perspective. This code acts as an intermediary between the client application (such as a web or mobile app) and the API resource server, allowing the client to send requests and receive responses in a structured manner.

Client code typically includes functions or methods corresponding to the operations defined in the API, such as making HTTP requests (e.g., GET, POST, PUT) to specific endpoints, handling authentication, and parsing responses. By generating client code from an OpenAPI specification, developers can automate the process of creating these interactions, ensuring consistency and accuracy in how their applications communicate with the API.

Creating a client for the API is a crucial aspect of integrating our services into your application. Using a standardized definition such as OpenAPI 3.0 schemas offers numerous benefits:

  • Consistency : By following a standard schema, consistency in how developments interact with the API is ensured, reducing errors and misunderstandings.
  • Efficiency : It is possible to quickly generate client code based on the API specification, saving time and effort.
  • Accuracy : The generated code is based directly on the API definition, reducing the risk of discrepancies between documentation and implementation.
  • Ease of Maintenance : Any changes to the API can be quickly reflected in the client code by regenerating it from the updated schema.

Tool

To generate client code from an OpenAPI 3.0 schema, we recommend using openapi-generator, available on GitHub - OpenAPITools/openapi-generator. This tool allows you to generate client libraries for various programming languages (currently supporting over 50) using a simple command-line interface (CLI).

Using the OpenAPI Generator CLI

  • Installation : First, ensure you have Java installed on your system, as the openapi generator is written in Java.
  • Download OpenAPI Generator : You can download the latest version of the openapi-generator-cli.jar file by following these instructions .
  • Download OpenAPI Definition : You can use the version provided here and save the JSON file to a local path, for example, /code/client .
  • Generate Client Code : Using the JAR file, you can generate client code using the following command (adjust the file path and/or name if necessary):
Copy
Copied
cd /code/client
java -jar openapi-generator-cli.jar generate -i swagger.json \ 
-g <language> -o <output_folder>

Replace <language> with the desired programming language (e.g., java, php, javascript, csharp) and <output_folder> with the folder where you want the generated code to be saved. If you want to generate the output in the same folder from where the command was executed, you can omit -o <output_folder>. The link here provides documentation on the command properties and configuration options specific to each language.

Alternatively, there are the following options to use openapi-generator without using the JAR file:

  • Installing the generator via homebrew (on OSX)
  • Docker
  • NPM package

Refer to the official OpenAPI Generator documentation for installation details.

By using this code generator, you can quickly generate client libraries for the desired programming language and start seamlessly integrating with our Instant Payment API.