You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cognitive-services/Bing-Web-Search/quickstarts/csharp.md
+19-13Lines changed: 19 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,17 @@ manager: nitinme
8
8
ms.service: cognitive-services
9
9
ms.subservice: bing-web-search
10
10
ms.topic: quickstart
11
-
ms.date: 12/09/2019
11
+
ms.date: 05/22/2020
12
12
ms.author: aahi
13
13
ms.custom: seodec2018
14
14
#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#.
15
15
---
16
16
17
17
# Quickstart: Search the web using the Bing Web Search REST API and C#
18
18
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 in this quickstart uses only .NET Core classes.
20
22
21
23
## Prerequisites
22
24
@@ -26,13 +28,11 @@ Here are a few things that you'll need before running this quickstart:
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. Add this code to the `Program` class you created in the previous section:
62
+
63
+
1. For the `uriBase` value, 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.
64
+
65
+
2. Confirm that `uriBase` is valid and replace the `accessKey` value with a subscription key from your Azure account.
66
+
67
+
3. Optionally, customize the search query by replacing the value for `searchTerm`.
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.
83
+
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.
78
84
79
-
Keep in mind that `main()` is dependent on methods that are created in the next few sections.
85
+
The `main()`method is dependent on methods that you create in the next sections.
80
86
81
87
```csharp
82
88
staticvoidMain()
@@ -105,7 +111,7 @@ static void Main()
105
111
106
112
## Create a struct for search results
107
113
108
-
This struct returns search results with relevant headers. It's called when making a request to the Bing Web Search API to create a result object.
114
+
Create a struct that returns search results with relevant headers. You call it when you make a request to the Bing Web Search API to create a result object.
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).
240
+
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).
235
241
236
-
## Sample response
242
+
## Example JSON response
237
243
238
244
Responses from the Bing Web Search API are returned as JSON. This sample response has been truncated to show a single result.
239
245
@@ -362,6 +368,6 @@ Responses from the Bing Web Search API are returned as JSON. This sample respons
362
368
## Next steps
363
369
364
370
> [!div class="nextstepaction"]
365
-
> [Bing Web search single-page app tutorial](../tutorial-bing-web-search-single-page-app.md)
371
+
> [Bing Web Search API single-page app tutorial](../tutorial-bing-web-search-single-page-app.md)
# Quickstart: Search the web using the Bing Web Search REST API and Go
19
19
20
-
Use this quickstart to make your first call to the Bing Web Search API and receive the JSON response. This Go application sends a search request to the API, and shows the response. While this application is written in Go, the API is a RESTful Web service compatible with most programming languages.
20
+
Use this quickstart to make your first call to the Bing Web Search API. This Go application sends a search request to the API, and shows the JSON response. Although this application is written in Go, the API is a RESTful Web service compatible with most programming languages.
21
+
22
+
The code examples in this quickstart require only core libraries; there are no external dependencies.
21
23
22
24
## Prerequisites
23
25
Here are a few things that you'll need before running this quickstart:
24
26
25
27
*[Go binaries](https://golang.org/dl/)
26
28
* A subscription key
27
29
28
-
This quickstart only requires **core** libraries, there are no external dependencies.
Create a new Go project in your favorite IDE or editor. Then import `net/http` for requests, `ioutil` to read the response, `time` and `encoding/json` to handle the JSON, and `fmt` to print the output.
34
+
Create a new Go project in your favorite IDE or editor. Then, import `net/http` for requests, `ioutil` to read the response, `time` and `encoding/json` to handle the JSON, and `fmt` to print the output.
35
35
36
36
```go
37
37
package main
@@ -107,7 +107,13 @@ type BingAnswer struct {
107
107
108
108
## Declare the main function and define variables
109
109
110
-
This code declares the main function and sets required variables. `endpoint` 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 endpoint is correct and replace the `token` value with a valid subscription key from your Azure account. Feel free to customize the search query by replacing the value for `searchTerm`.
110
+
This code declares the main function and sets the required variables:
111
+
112
+
1. For the `endpoint` value, 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.
113
+
114
+
2. Confirm that the endpoint is correct and replace the `token` value with a valid subscription key from your Azure account.
115
+
116
+
3. Optionally, customize the search query by replacing the value for `searchTerm`.
111
117
112
118
```go
113
119
// Declare the main function. This is required for all Go programs.
@@ -166,7 +172,7 @@ if err != nil {
166
172
167
173
## Handle the response
168
174
169
-
Remember the struct we created earlier? We're going to use it to format the response and print the search results.
175
+
Use the struct we created previously to format the response and print the search results.
170
176
171
177
```go
172
178
// Create a new answer.
@@ -183,7 +189,7 @@ for _, result := range ans.WebPages.Value {
183
189
184
190
## Put it all together
185
191
186
-
The last step is to validate your code and run it! If you'd like to compare your code with ours, here's the complete program:
192
+
The last step is to validate your code and run it. If you'd like to compare your code with ours, here's the complete program:
187
193
188
194
```go
189
195
package main
@@ -301,9 +307,9 @@ func main() {
301
307
}
302
308
```
303
309
304
-
## Sample response
310
+
## Example JSON response
305
311
306
-
Responses from the Bing Web Search API are returned as JSON. This sample response has been formatted using the `BingAnswer` struct and shows the `result.Name` and `result.URL`.
312
+
Responses from the Bing Web Search API are returned as JSON. This sample response has been formatted by using the `BingAnswer` struct and shows the `result.Name` and `result.URL`.
307
313
308
314
```go
309
315
Microsoft CognitiveServices || https://www.microsoft.com/cognitive-services
#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.
15
15
---
16
16
17
17
# Quickstart: Use Java to search the web with the Bing Web Search REST API, an Azure cognitive service
18
18
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.
If you're using Maven, declare Gson in the `POM.xml`. Skip this step if you've installed Gson locally.
48
+
If you're using Maven, declare Gson in POM.xml. Skip this step if you've installed Gson locally.
49
49
50
50
```xml
51
51
<dependency>
@@ -57,7 +57,7 @@ If you're using Maven, declare Gson in the `POM.xml`. Skip this step if you've i
57
57
58
58
## Declare the BingWebSearch class
59
59
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.
61
61
62
62
```java
63
63
publicclassBingWebSearch {
@@ -69,7 +69,13 @@ public class BingWebSearch {
69
69
70
70
## Define variables
71
71
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
+
The following code sets the `subscriptionKey`, `host`, `path`, and `searchTerm`. Add this code to the `BingWebSearch` class described in the previous section:
73
+
74
+
1. For the `host` value, 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.
75
+
76
+
2. Replace the `subscriptionKey` value with a valid subscription key from your Azure account.
77
+
78
+
3. Optionally, customize the search query by replacing the value for `searchTerm`.
This method, which lives in the `BingWebSearch` class, constructs the `url`, receives and parses the response, and extracts Bing-related HTTP headers.
96
+
The `SearchWeb()`method, which is included in the `BingWebSearch` class, constructs the `url`, receives and parses the response, and extracts Bing-related HTTP headers.
@@ -133,7 +139,7 @@ public static String prettify(String json_text) {
133
139
134
140
## Declare the main method
135
141
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.
142
+
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 then prints the JSON response.
137
143
138
144
```java
139
145
publicstaticvoid main (String[] args) {
@@ -163,7 +169,7 @@ public static void main (String[] args) {
163
169
164
170
## Create a container class for search results
165
171
166
-
The `SearchResults` container class is outside of the `BingWebSearch` class. It includes relevant headers and JSON data for the response.
172
+
The `SearchResults` container class is defined outside of the `BingWebSearch` class. It includes relevant headers and JSON data for the response.
167
173
168
174
```java
169
175
classSearchResults{
@@ -178,7 +184,7 @@ class SearchResults{
178
184
179
185
## Put it all together
180
186
181
-
The last step is to compile your code and run it! Here are the commands:
187
+
The last step is to compile your code and run it. Use the following commands:
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).
189
195
190
-
## Sample response
196
+
## Example JSON response
191
197
192
198
Responses from the Bing Web Search API are returned as JSON. This sample response has been truncated to show a single result.
193
199
@@ -316,6 +322,6 @@ Responses from the Bing Web Search API are returned as JSON. This sample respons
316
322
## Next steps
317
323
318
324
> [!div class="nextstepaction"]
319
-
> [Bing Web search single-page app tutorial](../tutorial-bing-web-search-single-page-app.md)
325
+
> [Bing Web Search API single-page app tutorial](../tutorial-bing-web-search-single-page-app.md)
0 commit comments