Skip to content

Commit 44f0802

Browse files
author
dksimpson
committed
Refresh Bing Web Search REST API quickstarts
1 parent 70f6cc1 commit 44f0802

File tree

7 files changed

+69
-66
lines changed

7 files changed

+69
-66
lines changed

articles/cognitive-services/Bing-Web-Search/quickstarts/csharp.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: bing-web-search
1010
ms.topic: quickstart
11-
ms.date: 12/09/2019
11+
ms.date: 05/20/2020
1212
ms.author: aahi
1313
ms.custom: seodec2018
1414
#Customer intent: As a new developer, I want to make my first call to the Bing Web Search API and receive a response using C#.
1515
---
1616

1717
# Quickstart: Search the web using the Bing Web Search REST API and C#
1818

19-
Use this quickstart to make your first call to the Bing Web Search API and receive the JSON response. This C# application sends a search request to the API, and shows the response. While this application is written in C#, the API is a RESTful Web service compatible with most programming languages.
19+
Use this quickstart to make your first call to the Bing Web Search API. This C# application sends a search request to the API, and shows the JSON response. Although this application is written in C#, the API is a RESTful Web service compatible with most programming languages.
20+
21+
This example program only uses .NET Core classes.
2022

2123
## Prerequisites
2224

@@ -26,13 +28,11 @@ Here are a few things that you'll need before running this quickstart:
2628
* Linux/macOS: [Mono](https://www.mono-project.com/)
2729
* A subscription key
2830

29-
This example program only uses .NET Core classes.
30-
3131
[!INCLUDE [bing-web-search-quickstart-signup](../../../../includes/bing-web-search-quickstart-signup.md)]
3232

3333
## Create a project and declare dependencies
3434

35-
Create a new project in Visual Studio or Mono. Then use this code to import required namespaces and types.
35+
Create a new project in Visual Studio or Mono. Use the following code to import the required namespaces and types:
3636

3737
```csharp
3838
using System;
@@ -58,7 +58,7 @@ namespace BingSearchApisQuickstart
5858

5959
## Define variables
6060

61-
A few variables must be set before we can continue. `uriBase` can be the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource. Confirm that the `uriBase` is valid and replace the `accessKey` value with a valid subscription key from your Azure account. Feel free to customize the search query by replacing the value for `searchTerm`. Remember to add this code to the `Program` class as noted above.
61+
A few variables must be set before we can continue. You can use the value of `uriBase` in the following code for the global endpoint, or use the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource. Confirm that `uriBase` is valid and replace the `accessKey` value with a valid subscription key from your Azure account. You can customize the search query by replacing the value for `searchTerm`. Add this code to the `Program` class as noted in the previous section.
6262

6363
```csharp
6464
// Enter a valid subscription key.
@@ -74,7 +74,7 @@ const string searchTerm = "Microsoft Cognitive Services";
7474

7575
## Declare the Main method
7676

77-
The `Main()` method is required and it's the first method invoked when the program is started. In this application, the main method validates the `accessKey`, makes a request, and prints the response.
77+
The `Main()` method is required and is the first method invoked when you start the program. In this application, the main method validates the `accessKey`, makes a request, and prints the response.
7878

7979
Keep in mind that `main()` is dependent on methods that are created in the next few sections.
8080

@@ -231,9 +231,9 @@ static string JsonPrettyPrint(string json)
231231

232232
## Put it all together
233233

234-
The last step is to run your code! If you'd like to compare your code with ours, [sample code is available on GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/dotnet/Search/BingWebSearchv7.cs).
234+
The last step is to run your code. If you'd like to compare your code with ours, see the [sample code on GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/dotnet/Search/BingWebSearchv7.cs).
235235

236-
## Sample response
236+
## Example JSON response
237237

238238
Responses from the Bing Web Search API are returned as JSON. This sample response has been truncated to show a single result.
239239

articles/cognitive-services/Bing-Web-Search/quickstarts/java.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: bing-web-search
1010
ms.topic: quickstart
11-
ms.date: 12/09/2019
11+
ms.date: 05/20/2020
1212
ms.author: aahi
1313
ms.custom: seodec2018, seo-java-july2019, seo-java-august2019, seo-java-september2019
1414
#Customer intent: As a new developer, I want to make my first call to the Bing Web Search API and receive a response using Java.
1515
---
1616

1717
# Quickstart: Use Java to search the web with the Bing Web Search REST API, an Azure cognitive service
1818

19-
In this quickstart, you'll use a Java application to make your first call to the Bing Web Search API and receive the JSON response. This Java application sends a search request to the API, and shows the response. While this application is written in Java, the API is a RESTful Web service compatible with most programming languages.
19+
In this quickstart, you'll use a Java application to make your first call to the Bing Web Search API. This Java application sends a search request to the API, and shows the JSON response. Although this application is written in Java, the API is a RESTful Web service compatible with most programming languages.
2020

2121
## Prerequisites
2222

@@ -57,7 +57,7 @@ If you're using Maven, declare Gson in the `POM.xml`. Skip this step if you've i
5757

5858
## Declare the BingWebSearch class
5959

60-
Declare the `BingWebSearch` class. It will include most of the code we review in this quickstart including the `main` method.
60+
Declare the `BingWebSearch` class. It includes most of the code we review in this quickstart, including the `main()` method.
6161

6262
```java
6363
public class BingWebSearch {
@@ -69,7 +69,7 @@ public class BingWebSearch {
6969

7070
## Define variables
7171

72-
This code sets the `subscriptionKey`, `host`, `path`, and `searchTerm`. `host` can be the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource. Replace the `subscriptionKey` value with a valid subscription key from your Azure account. Feel free to customize the search query by replacing the value for `searchTerm`. Remember to add this code to the `BingWebSearch` class as noted above.
72+
This code sets the `subscriptionKey`, `host`, `path`, and `searchTerm`. You can use the value of `host` in the following code for the global endpoint, or use the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource. Replace the `subscriptionKey` value with a valid subscription key from your Azure account. You can customize the search query by replacing the value for `searchTerm`. Add this code to the `BingWebSearch` class as noted in the previous section.
7373

7474
```java
7575
// Enter a valid subscription key.
@@ -87,7 +87,7 @@ static String searchTerm = "Microsoft Cognitive Services";
8787

8888
## Construct a request
8989

90-
This method, which lives in the `BingWebSearch` class, constructs the `url`, receives and parses the response, and extracts Bing-related HTTP headers.
90+
This method, which is included in the `BingWebSearch` class, constructs the `url`, receives and parses the response, and extracts Bing-related HTTP headers.
9191

9292
```java
9393
public static SearchResults SearchWeb (String searchQuery) throws Exception {
@@ -133,7 +133,7 @@ public static String prettify(String json_text) {
133133

134134
## Declare the main method
135135

136-
This method is required and is the first method invoked when the program is started. In this application, it includes code that validates the `subscriptionKey`, makes a request, and prints the JSON response.
136+
The `main()` method is required and is the first method invoked when you start the program. In this application, it includes code that validates the `subscriptionKey`, makes a request, and prints the JSON response.
137137

138138
```java
139139
public static void main (String[] args) {
@@ -178,7 +178,7 @@ class SearchResults{
178178

179179
## Put it all together
180180

181-
The last step is to compile your code and run it! Here are the commands:
181+
The last step is to compile your code and run it. Use the following commands:
182182

183183
```powershell
184184
javac BingWebSearch.java -classpath ./gson-2.8.5.jar -encoding UTF-8
@@ -187,7 +187,7 @@ java -cp ./gson-2.8.5.jar BingWebSearch
187187

188188
If you'd like to compare your code with ours, [sample code is available on GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/java/Search/BingWebSearchv7.java).
189189

190-
## Sample response
190+
## Example JSON response
191191

192192
Responses from the Bing Web Search API are returned as JSON. This sample response has been truncated to show a single result.
193193

@@ -316,6 +316,6 @@ Responses from the Bing Web Search API are returned as JSON. This sample respons
316316
## Next steps
317317

318318
> [!div class="nextstepaction"]
319-
> [Bing Web search single-page app tutorial](../tutorial-bing-web-search-single-page-app.md)
319+
> [Bing Web Search API single-page app tutorial](../tutorial-bing-web-search-single-page-app.md)
320320
321321
[!INCLUDE [bing-web-search-quickstart-see-also](../../../../includes/bing-web-search-quickstart-see-also.md)]

articles/cognitive-services/Bing-Web-Search/quickstarts/nodejs.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: bing-web-search
1010
ms.topic: quickstart
11-
ms.date: 12/09/2019
11+
ms.date: 05/20/2020
1212
ms.author: aahi
1313
ms.custom: seodec2018
1414
#Customer intent: As a new developer, I want to make my first call to the Bing Web Search API and receive a response using Node.js.
1515
---
1616

1717
# Quickstart: Search the web using the Bing Web Search REST API and Node.js
1818

19-
Use this quickstart to make your first call to the Bing Web Search API and receive the JSON response. This Node.js application sends a search request to the API, and shows the response. While this application is written in JavaScript, the API is a RESTful Web service compatible with most programming languages.
19+
Use this quickstart to make your first call to the Bing Web Search API. This Node.js application sends a search request to the API, and shows the JSON response. Although this application is written in JavaScript, the API is a RESTful Web service compatible with most programming languages.
2020

2121
## Prerequisites
2222

@@ -29,8 +29,7 @@ Here are a few things that you'll need before running this quickstart:
2929

3030
## Create a project and declare required modules
3131

32-
Create a new Node.js project in your favorite IDE or editor.
33-
Then copy the code snippet below into your project in a file named `search.js`.
32+
Create a new Node.js project in your favorite IDE or editor. Then, copy the following code snippet to your project in a file named `search.js`:
3433

3534
```javascript
3635
// Use this simple app to query the Bing Web Search API and get a JSON response.
@@ -40,9 +39,9 @@ const https = require('https')
4039

4140
## Set the subscription key
4241

43-
This code snippet uses the `AZURE_SUBSCRIPTION_KEY` environment variable to store your subscription key, a good practice to prevent the accidental exposure of your keys when deploying code. Go to the [Your APIs page](https://azure.microsoft.com/try/cognitive-services/my-apis/?apiSlug=search-api-v7) to look up your subscription key.
42+
This code snippet uses the `AZURE_SUBSCRIPTION_KEY` environment variable to store your subscription key, which is a good practice to prevent the accidental exposure of your keys when deploying code. To look up your subscription key, see [Your APIs](https://azure.microsoft.com/try/cognitive-services/my-apis/?apiSlug=search-api-v7).
4443

45-
If you're unfamiliar with using environment variables, or looking to run this app as fast as possible, then you can replace `process.env['AZURE_SUBSCRIPTION_KEY']` with your subscription key set as a string.
44+
If you're unfamiliar with the use of environment variables, or you want to run this app as fast as possible, replace `process.env['AZURE_SUBSCRIPTION_KEY']` with your subscription key set as a string.
4645

4746
```javascript
4847
const SUBSCRIPTION_KEY = process.env['AZURE_SUBSCRIPTION_KEY']
@@ -53,7 +52,9 @@ if (!SUBSCRIPTION_KEY) {
5352

5453
## Create a function to make the request
5554

56-
This function will make a secure GET request, saving the search query as a query parameter in the path. `hostname` can be the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource. `encodeURIComponent` is used to escape invalid characters, and the subscription key is passed in a header. The callback receives a [response](https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_class_http_serverresponse) that subscribes to the `data` event to aggregate the JSON body, the `error` event to log any issues, and the `end` event to know when the message should be considered complete. When complete, the app will print the interesting headers and message body. You can play with the colors and set the depth to suit your preference, a depth of `1` gives a nice summary of the response.
55+
This function makes a secure GET request and saves the search query as a query parameter in the path. You can use the value of `hostname` in the following code for the global endpoint, or use the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
56+
57+
In this function, `encodeURIComponent` is used to escape invalid characters, and the subscription key is passed in a header. The callback receives a [response](https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_class_http_serverresponse) that subscribes to the `data` event to aggregate the JSON body, the `error` event to log any issues, and the `end` event to know when the message should be considered complete. When complete, the app prints the interesting headers and message body. You can adjust the colors and set the depth to suit your preference. A depth of `1` gives a nice summary of the response.
5758

5859
```javascript
5960
function bingWebSearch(query) {
@@ -83,15 +84,15 @@ function bingWebSearch(query) {
8384

8485
## Get the query
8586

86-
Let's look at the program's arguments to find the query. The first argument is the path to node, the second is our filename, and the third is your query. If the query is absent, a default query of "Microsoft Cognitive Services" is used.
87+
Let's look at the program's arguments to find the query. The first argument is the path to the node, the second is our filename, and the third is your query. If the query is absent, a default query of "Microsoft Cognitive Services" is used.
8788

8889
```javascript
8990
const query = process.argv[2] || 'Microsoft Cognitive Services'
9091
```
9192

9293
## Make a request and print the response
9394

94-
And now that everything is defined, let's call our function!
95+
And now that everything is defined, let's call our function.
9596

9697
```javascript
9798
bingWebSearch(query)
@@ -136,7 +137,7 @@ const query = process.argv[2] || 'Microsoft Cognitive Services'
136137
bingWebSearch(query)
137138
```
138139

139-
## Sample response
140+
## Example JSON response
140141

141142
Responses from the Bing Web Search API are returned as JSON. This sample response has been truncated to show a single result.
142143

articles/cognitive-services/Bing-Web-Search/quickstarts/php.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: bing-web-search
1010
ms.topic: quickstart
11-
ms.date: 12/09/2019
11+
ms.date: 05/20/2020
1212
ms.author: aahi
1313
ms.custom: seodec2018
1414
#Customer intent: As a new developer, I want to make my first call to the Bing Web Search API and receive a response using PHP.
@@ -151,7 +151,7 @@ if (strlen($accessKey) == 32) {
151151
?>
152152
```
153153

154-
## Sample response
154+
## Example JSON response
155155

156156
Responses from the Bing Web Search API are returned as JSON. This sample response has been truncated to show a single result.
157157

articles/cognitive-services/Bing-Web-Search/quickstarts/python.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ manager: nitinme
88
ms.service: cognitive-services
99
ms.subservice: bing-web-search
1010
ms.topic: quickstart
11-
ms.date: 12/09/2019
11+
ms.date: 05/20/2020
1212
ms.author: aahi
1313
ms.custom: seodec2018
1414
#Customer intent: As a new developer, I want to make my first call to the Bing Web Search API and receive a response using Python.
1515
---
1616

1717
# Quickstart: Use Python to call the Bing Web Search API
1818

19-
Use this quickstart to make your first call to the Bing Web Search API and receive the JSON response. This Python application sends a search request to the API, and shows the response. While this application is written in Python, the API is a RESTful Web service compatible with most programming languages.
19+
Use this quickstart to make your first call to the Bing Web Search API. This Python application sends a search request to the API, and shows the JSON response. Although this application is written in Python, the API is a RESTful Web service compatible with most programming languages.
2020

2121
This example is run as a Jupyter notebook on [MyBinder](https://mybinder.org). Select the launch binder badge:
2222

@@ -30,28 +30,30 @@ This example is run as a Jupyter notebook on [MyBinder](https://mybinder.org). S
3030

3131
## Define variables
3232

33-
Replace the `subscription_key` value with a valid subscription key from your Azure account.
33+
1. Replace the `subscription_key` value with a valid subscription key from your Azure account.
3434

35-
```python
36-
subscription_key = "YOUR_ACCESS_KEY"
37-
assert subscription_key
38-
```
35+
```python
36+
subscription_key = "YOUR_ACCESS_KEY"
37+
assert subscription_key
38+
```
3939

40-
Declare the Bing Web Search API endpoint. You can use the global endpoint below, or the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
40+
2. Declare the Bing Web Search API endpoint. You can use the global endpoint in the following code, or use the [custom subdomain](../../../cognitive-services/cognitive-services-custom-subdomains.md) endpoint displayed in the Azure portal for your resource.
4141

42-
```python
43-
search_url = "https://api.cognitive.microsoft.com/bing/v7.0/search"
44-
```
42+
```python
43+
search_url = "https://api.cognitive.microsoft.com/bing/v7.0/search"
44+
```
4545

46-
Feel free to customize the search query by replacing the value for `search_term`.
46+
3. Optionally, customize the search query by replacing the value for `search_term`.
4747

48-
```python
49-
search_term = "Azure Cognitive Services"
50-
```
48+
```python
49+
search_term = "Azure Cognitive Services"
50+
```
5151

5252
## Make a request
5353

54-
This block uses the `requests` library to call the Bing Web Search API and return the results as a JSON object. The API key is passed in the `headers` dictionary, and the search term and query parameters are passed in the `params` dictionary. See [Bing Web Search API v7](https://docs.microsoft.com/rest/api/cognitiveservices-bingsearch/bing-web-api-v7-reference) documentation for a complete list of options and parameters.
54+
This code uses the `requests` library to call the Bing Web Search API and return the results as a JSON object. The API key is passed in the `headers` dictionary, and the search term and query parameters are passed in the `params` dictionary.
55+
56+
For a complete list of options and parameters, see [Bing Web Search API v7](https://docs.microsoft.com/rest/api/cognitiveservices-bingsearch/bing-web-api-v7-reference).
5557

5658
```python
5759
import requests
@@ -65,7 +67,7 @@ search_results = response.json()
6567

6668
## Format and display the response
6769

68-
The `search_results` object includes the search results and metadata like related queries and pages. This code uses the `IPython.display` library to format and display the response in your browser.
70+
The `search_results` object includes the search results and metadata such as related queries and pages. This code uses the `IPython.display` library to format and display the response in your browser.
6971

7072
```python
7173
from IPython.display import HTML
@@ -80,7 +82,7 @@ HTML("<table>{0}</table>".format(rows))
8082

8183
## Sample code on GitHub
8284

83-
If you'd like to run this code locally, the complete [sample is available on GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/python/Search/BingWebSearchv7.py).
85+
To run this code locally, see the complete [sample available on GitHub](https://github.com/Azure-Samples/cognitive-services-REST-api-samples/blob/master/python/Search/BingWebSearchv7.py).
8486

8587
## Next steps
8688

0 commit comments

Comments
 (0)