Created
September 9, 2023 10:10
-
-
Save kvii/a526cc8e07071db87d212ca3209d7863 to your computer and use it in GitHub Desktop.
A http client that support baseUrl.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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