Module bing.autosuggest
ballerinax/bing.autosuggest Ballerina library
Overview
This is a generated connector for Bing Autosuggest API v1 OpenAPI specification. The Autosuggest API lets partners send a partial search query to Bing and get back a list of suggested queries that other users have searched on. In addition to including searches that other users have made, the list may include suggestions based on user intent. For example, if the query string is weather in Lo, the list will include relevant weather suggestions.
This module supports Bing Autosuggest API v1.
Prerequisites
Before using this connector in your Ballerina application, complete the following:
-
Create an Azure account
-
Create a Bing Resource
-
Obtain tokens by following this guide
Quickstart
To use the Bing Autosuggest connector in your Ballerina application, update the .bal file as follows:
Step 1: Import connector
Import the ballerinax/bing.autosuggest
module into the Ballerina project.
import ballerinax/bing.autosuggest;
Step 2: Create a new connector instance
You can now make the connection configuration using Ocp-Apim-Subscription-Key
.
You can do this step in two ways. You can use any one of this.
-
Option 1 : Configure API Keys in ballerina file directly.
uggest:ApiKeysConfig apiKeyConfig = { cpApimSubscriptionKey:"<AZURE_API_KEY>" ubscriptionKey: "<Subscription Key>" uggest:Client myClient = check new Client(apiKeyConfig, serviceUrl);
-
Option 2 : Configure API Keys in
Config.toml
file and configure it in ballerina file, using configurables.- Set up API Keys in
Config.toml
as shown below.
[apiKeyConfig.apiKeys] ocpApimSubscriptionKey = "<AZURE_API_KEY>" subscriptionKey = "<Subscription Key>"
- Configure the client in ballerina file as shown below.
configurable ApiKeysConfig & readonly apiKeyConfig = ?; autosuggest:Client myClient = check new Client(apiKeyConfig, serviceUrl);
- Set up API Keys in
Step 3: Invoke connector operation
-
Now you can use the operations available within the connector. Note that they are in the form of remote operations.
Following operation provides suggestions for a given query or partial query.
public function main() returns error? { autosuggest:SentimentResponse res = check baseClient->sentiment(query); }
-
Use
bal run
command to compile and run the Ballerina program.