Skip to content

Instantly share code, notes, and snippets.

@kvii
Created September 9, 2023 10:10
Show Gist options
  • Save kvii/a526cc8e07071db87d212ca3209d7863 to your computer and use it in GitHub Desktop.
Save kvii/a526cc8e07071db87d212ca3209d7863 to your computer and use it in GitHub Desktop.
A http client that support baseUrl.
import 'package:http/http.dart' as http;
class MyClient with http.BaseClient {
final _client = http.Client();
final Uri baseUrl;
MyClient(this.baseUrl);
@override
Future<http.StreamedResponse> send(http.BaseRequest request) {
final url = baseUrl.resolveUri(request.url);
return _client.send(MyRequest(request.method, url));
}
@override
void close() {
_client.close();
super.close();
}
}
class MyRequest extends http.BaseRequest {
MyRequest(super.method, super.url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment