Skip to content

Commit 2148ec0

Browse files
committed
feat(dart): add example
1 parent cdbaf2e commit 2148ec0

File tree

1 file changed

+40
-0
lines changed
  • clients/algoliasearch-client-dart/packages/chopper_requester/example

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import 'package:algolia_chopper_requester/algolia_chopper_requester.dart';
2+
import 'package:algolia_client_core/algolia_client_core.dart';
3+
4+
void main() async {
5+
const String appId = 'latency';
6+
const String apiKey = '6be0576ff61c053d5f9a3225e2a90f76';
7+
8+
// Creating an instance of the RetryStrategy with necessary parameters.
9+
// This will retry the failed requests with a backoff strategy.
10+
final requester = RetryStrategy.create(
11+
segment: AgentSegment(value: 'CustomClient'),
12+
appId: appId,
13+
apiKey: apiKey,
14+
defaultHosts: () => [
15+
Host(url: 'latency-dsn.algolia.net'),
16+
Host(url: 'latency-1.algolianet.com'),
17+
],
18+
options: ClientOptions(
19+
requester: ChopperRequester(
20+
appId: appId,
21+
apiKey: apiKey,
22+
),
23+
),
24+
);
25+
26+
// Executing a GET request on the '/1/indexes/instant_search' endpoint.
27+
final response = await requester.execute(
28+
request: ApiRequest(
29+
method: RequestMethod.get,
30+
path: '/1/indexes/instant_search',
31+
queryParams: {'query': 'a', 'hitsPerPage': '5'},
32+
),
33+
);
34+
35+
// Printing json response.
36+
print(response);
37+
38+
// Dispose of the requester to clean up its resources.
39+
requester.dispose();
40+
}

0 commit comments

Comments
 (0)