1
+ import 'dart:io' show HttpClient;
2
+
1
3
import 'package:algolia_chopper_requester/algolia_chopper_requester.dart' ;
2
4
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;
3
7
4
8
void main () async {
5
9
const String appId = 'latency' ;
6
10
const String apiKey = '6be0576ff61c053d5f9a3225e2a90f76' ;
7
11
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
+
8
17
// Creating an instance of the RetryStrategy with necessary parameters.
9
18
// This will retry the failed requests with a backoff strategy.
10
- final requester = RetryStrategy .create (
19
+ final RetryStrategy requester = RetryStrategy .create (
11
20
segment: AgentSegment (value: 'CustomClient' ),
12
21
appId: appId,
13
22
apiKey: apiKey,
@@ -19,12 +28,13 @@ void main() async {
19
28
requester: ChopperRequester (
20
29
appId: appId,
21
30
apiKey: apiKey,
31
+ client: client,
22
32
),
23
33
),
24
34
);
25
35
26
36
// 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 (
28
38
request: ApiRequest (
29
39
method: RequestMethod .get ,
30
40
path: '/1/indexes/instant_search' ,
@@ -37,4 +47,7 @@ void main() async {
37
47
38
48
// Dispose of the requester to clean up its resources.
39
49
requester.dispose ();
50
+
51
+ // Disposing a custom client has to be done manually.
52
+ client.close ();
40
53
}
0 commit comments