roundtripper 0.2.1 roundtripper: ^0.2.1 copied to clipboard
another composable, Future-based library for making HTTP requests
Another composable, multi-platform HTTP client
Totally inspected by http.RoundTripper from golang, and dart style fit. Based on dio for crossing-platforms support.
You could do any processing for each request in RoundTrip
.
- Logging.
- Throws non-2xx Response as Error.
- Request/Response Body Encoding.
Using #
import 'package:roundtripper/roundtripper.dart';
import 'package:roundtripper/roundtripbuilders/request_body_convert.dart';
import 'package:roundtripper/roundtripbuilders/request_log.dart';
import 'package:roundtripper/roundtripbuilders/throws_not_2xx_error.dart';
var c = Client(roundTripBuilders: [
ThrowsNot2xxError(),
RequestBodyConvert(),
RequestLog(logger),
]);
void main() async {
var resp = await c.fetch(Request.uri(
"$httpBinEndpoint/anything",
queryParameters: {
"int": 1,
"slice": [1, 2],
},
headers: {
"x-int": 1,
"x-slice": [1, 2],
},
));
try {
var json = await resp.json();
} on ErrorResponse catch (e) {
// e.response
}
}