-
Navigate to https://functions.azure.com/try (free trial environmnet).
-
We’ll create an HTTP triggered function with JavaScript. On the screen below, select Webhook + API for the scenario, and choose JavaScript for the language. Click “Create this Function”
- You’ll see your new function and the function editor window shown below. You can view your files by clicking View files on the right pane.
- Let's test the sample function code under the Test tab on the right pane. In the Request body, change "Azure"" to your name.
- Hit the "Run"" button at the bottom of the screen. In the Output window, you'll see the response.
-
Navigate to https://azure.microsoft.com/en-us/try/cognitive-services/
-
Next to Computer Vision API, click the "Get API Key button. Agree to the terms, click Next, and then log in with your account of choice.
- Cognitive Services will provide you an endpoint and an API key. Note both of these items to use in your Azure Function
-
Navigate to https://github.com/laurentran/calhacksdemo/blob/master/GetCaption/index.js, and replace your function code (index.js) with the provided sample code.
-
One line 25, if the hostname of your provided Cognitive Service Computer Vision API is different than the sample, update it. The hostname should be:
{location}.api.cognitive.microsoft.com
. Do NOT include/vision/v1.0
in the hostname. -
On line 31, notice that the API key is stored as an environment variable:
process.env.API_KEY
. In the free version of Azure Function, we don't have access to storing environment variables, so we'll hard code in the API key. -
Substitute
process.env.API_KEY
with your API key. Be sure to use quotes around your string. (When you create an Azure account, you'll be able to create environment variables in the Application Settings). -
We're ready to test! In the right pane in the Test console, subsitute the Request Body with a request in the following format:
{
"imageURL" : "url.jpg"
}
- Find an image on Bing or Google, and provide the URL for the image. For example:
{
"imageURL": "http://cdn3-www.dogtime.com/assets/uploads/gallery/30-impossibly-cute-puppies/impossibly-cute-puppy-21.jpg"
}
- Click Run, and you should see the caption in the Output window from Cognitive Services!
- (Optional): To Test your Azure function outside of the provided testing console (i.e. using Postman or Curl), you can grab the function URL by clicking on </> Get function URL
Hooray!