Creating an API🔗

In many cases, the vision app is not a stand-alone application but a part of a bigger system. Although it is possible to handle all external interfaces such as cameras, network connections and I/O devices in the processing graph, the usual way is to expose a public API. Here, we’ll make our simple application to publish a single API function that lets client software to send an image for analysis.

First, open the Monochromatizer app in the Builder: press Ctrl+O, click the name of the project directory (“Monochromatizer”) and click “OK” or “Choose”. The exact looks of the file dialog depends on your operating system.

Since we are going to let clients send the image through the API, we don’t need a default value for the image input parameter. Reset the default value to an empty image by clicking the minus button in the value editor

Reset the default value of the image input.

Reset the default value of the image input.🔗

Right-click the tool to open a context menu. Select “Properties…”.

Use the context menu to configure tools.

Use the context menu to configure tools.🔗

Tick the “Publish tool function API” checkbox to expose the tool in the public API of the app. Add the image input and image output parameters to the interface by ticking the “Publish” checkbox. Accept the changes. You’ll see that the tool now has a nifty cloud icon. All of its inputs became disabled because the input data now comes through the API.

Select which parameters should go into an API function.

Select which parameters should go into an API function.🔗

Click the API button on the top right corner of the window to see what your API looks like.

The API editor shows the public API of the app.

The API editor shows the public API of the app.🔗

The Builder has an embedded HTTP server that lets you to test your app’s API while the app is running in the Builder. The server can be controlled by clicking the “HTTP” text on the status line. To activate the API you need to start the app by pressing F5. This enables the “Open in browser” button in the API editor. Let’s click it to open an API tester web page in your default browser.

The Builder’s built-in HTTP server provides a web GUI for testing APIs.

The Builder’s built-in HTTP server provides a web GUI for testing APIs.🔗

You can now use the browser or any other HTTP client to send images to your app for analysis. If you switch back to the builder, you can see the images there.

The browser-based API tester GUI can be used to test tool API functions. There is no ready-made GUI for other types of APIs, but it is easy to write your own client as explained here.

You are done with the API. Save the project by pressing Ctrl+S. It is time to create an installable component package.