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
Right-click the tool to open a context menu. Select “Properties…”.
Tick the “Publish tool function API” checkbox to expose the tool in the
public API of the app. Add the
image input and
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
Click the API button on the top right corner of the window to see what your API looks like.
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.
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.