Skip to content

Commit 9d25176

Browse files
committed
feat(dart): update example
1 parent 2148ec0 commit 9d25176

File tree

1 file changed

+15
-2
lines changed
  • clients/algoliasearch-client-dart/packages/chopper_requester/example

1 file changed

+15
-2
lines changed

clients/algoliasearch-client-dart/packages/chopper_requester/example/example.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
import 'dart:io' show HttpClient;
2+
13
import 'package:algolia_chopper_requester/algolia_chopper_requester.dart';
24
import 'package:algolia_client_core/algolia_client_core.dart';
5+
import 'package:http/http.dart' as http show Client;
6+
import 'package:http/io_client.dart' show IOClient;
37

48
void main() async {
59
const String appId = 'latency';
610
const String apiKey = '6be0576ff61c053d5f9a3225e2a90f76';
711

12+
// Create a custom http [Client] with a connection timeout of 30 seconds
13+
final http.Client client = IOClient(
14+
HttpClient()..connectionTimeout = const Duration(seconds: 30),
15+
);
16+
817
// Creating an instance of the RetryStrategy with necessary parameters.
918
// This will retry the failed requests with a backoff strategy.
10-
final requester = RetryStrategy.create(
19+
final RetryStrategy requester = RetryStrategy.create(
1120
segment: AgentSegment(value: 'CustomClient'),
1221
appId: appId,
1322
apiKey: apiKey,
@@ -19,12 +28,13 @@ void main() async {
1928
requester: ChopperRequester(
2029
appId: appId,
2130
apiKey: apiKey,
31+
client: client,
2232
),
2333
),
2434
);
2535

2636
// Executing a GET request on the '/1/indexes/instant_search' endpoint.
27-
final response = await requester.execute(
37+
final Map<String, dynamic> response = await requester.execute(
2838
request: ApiRequest(
2939
method: RequestMethod.get,
3040
path: '/1/indexes/instant_search',
@@ -37,4 +47,7 @@ void main() async {
3747

3848
// Dispose of the requester to clean up its resources.
3949
requester.dispose();
50+
51+
// Disposing a custom client has to be done manually.
52+
client.close();
4053
}

0 commit comments

Comments
 (0)