Azure Artificial Intelligence can be accessed by virtually any programming platform; all that is necessary is to formulate and send the appropriate http request and correctly parse the response. The Application Program Interface (API) is the same whether you prefer C#, Python, Node.js, or a host of other environments.
But what if you are just starting out and want only to see how Azure's AI APIs work? True, the Azure portal provides the API Console for some cognitive services such as text analytics, but not for all. If you want to get started with the Microsoft Cognitive APIs, you might want to download a convenient utility called Postman.
There are professional and team versions of Postman that must be licensed, but an individual version is available for free. Postman makes it easy to construct an HTTP request according to your specifications and view the response. Let's take a look at how simple it is to access Azure's translator service using Postman.
Of course, you must have an Azure subscription and have created a Translator service before you can proceed.
When you start Postman for the first time you will have to create a Postman account, and whatever you create will be stored on the Postman website under your account. We'll start by creating a collection to hold the various requests we create.
We'll call the collection "Translator".
Once we have a collection to hold our requests, we can select Add Request from the collection's menu.
The new request will have to be named and will have to be added to the Translator collection.
We open the Translator folder along the left and then click on the request name to open it in the Postman editing environment. We'll change the "GET" to "POST". For our URL we will extract the URL from a Microsoft curl example and paste it into Postman.
curl -X POST "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0&to=en" ...
Note that when we paste the URL into the form, the GET parameters are parsed into their own separate fields below. This works the other way, too. If we wished to add parameters we could type the name and value in the fields below and Postman would automatically add them to the URL.
Now we need to set header information as well as the request body itself. We click on the Header tab and make the appropriate entries. So far, all the information we have provided will be the same for any request sent to the Translator service. We might as well save what we have, and any specific requests to be made in the future can start with a copy of the request we have created here.
Obviously, you will have to obtain your access key from the Azure portal and paste it into the field you have labelled Ocp-Apim-Subscription-Key.
Now we are ready to go. We click on the Body tab and then ensure that the raw option button is selected. The JSON enclosing the text to be translated is pasted into the edit window. In these examples, we use character sets other than Roman to emphasize the range of capabilities of the Translator service.
Once the JSON is pasted into the request body, we can hit Send and scroll down in the same window to see the results. We observe that the Chinese characters for '5' and '4' have been intelligently (and correctly) translated as "May 4".
We can enclose multiples texts to be translated within a single JSON array. The texts need not be of the same language.
We see that the Thai script, roughly pronounced "som tam", translates to "papaya salad". By the way, if you think of salads as a cool dish, well, you've not yet been to Bangkok.
Postman is a powerful application for the development and testing of APIs. Even if you only use it to explore Azure APIs, as we did here, it is a very helpful tool and well worth the download.