-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhttp_service.dart
26 lines (24 loc) · 924 Bytes
/
http_service.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import 'package:http/http.dart';
import 'package:xrpl_dart/xrpl_dart.dart';
class RPCHttpService with XRPServiceProvider {
RPCHttpService(this.url, this.client,
{this.defaultTimeout = const Duration(seconds: 30)});
@override
final String url;
final Client client;
final Duration defaultTimeout;
@override
Future<XRPServiceResponse<T>> doRequest<T>(XRPRequestDetails params,
{Duration? timeout}) async {
if (params.type.isPostRequest) {
final response = await client
.post(params.toUri(url), headers: params.headers, body: params.body())
.timeout(timeout ?? defaultTimeout);
return params.toResponse(response.bodyBytes, response.statusCode);
}
final response = await client
.get(params.toUri(url), headers: params.headers)
.timeout(timeout ?? defaultTimeout);
return params.toResponse(response.bodyBytes, response.statusCode);
}
}