Building an API Client

Introduction [top]

Once you have created all the Resources and Interactions for your API, then you can build an API Client (or build an API Server) from the grammar you defined in the Designer

There are two components required to build an API Client: A JSON grammar file, and our Client API Framework. The framework interprets the grammar file and creates an easy to use Client to call the API from Lua within the Iguana translator.

Creating an API Client is easy — you just use the Generate option in the Designer and it automatically creates the all the Lua framework code for the Client.

There are two ways to create an API Server channel:

  1. Generate a project zip file and import it into a From HTTPS channel
  2. Generate the API Server channel directly into an Iguana instance that is accessible over the internet

Generate the API Client code [top]

First we need to generate the Client code that we will use in out client channel.

  1. Open your API and click on the Generate link.
  2. Generate a Client project zip file — Click the API Client Zip link:

Tip: If you are using a web enabled Iguana Translator to develop your interface then you can use the Direct option to export the API directly from the Designer into your Iguana instance.

Load the Client code [top]

Next we need to import that code into an Iguana Translator channel that we will use for the client.
Note: This step is not required if you chose the Direct option in the Tip above.

  1. Create a channel for the Client, with these properties:
    • Source: From HTTPS
    • Destination: To Channel
    • Channel Name: “<Your Client Name>” (omit the angle brackets “<>”)
    • URL Path: “<your-client-name>/”
  2. Import the client zip project file into the From HTTPS source of your channel.
  3. Update the placeholder values for the #SERVER_URL# and #ACCESS_TOKEN# in the main module:
    • Server: Open the channel properties for the API Server
    • Server: Copy the URL path from the Source properties tab
    • Client: Replace #SERVER_URL# with the copied path
    • Server: Click on the URL Path link (source properties tab) to open the channel endpoint
    • Server: Login using the User and Password for your Iguana instance
    • Server: Click the Generate Access Tokens button at the bottom of the page
    • Server: Enter a token name (we used “Test”), and click the Generate button
    • Server: Click the Show/Hide link and copy the revealed token
    • Client: Replace #ACCESS_TOKEN# with the copied token
    • Client: The replaced tokens should look something like this:

Leave A Comment?