Last active
August 22, 2021 16:33
-
-
Save johngorithm/c2ae6b7508dc6530f59318151febf27c to your computer and use it in GitHub Desktop.
This Rapper essentially makes it easy to test out code using the http dart library. It is plainly an abstraction to enhance testability
This file contains 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 'dart:typed_data'; | |
import 'package:http/http.dart' as http; | |
class HttpService { | |
Duration timeOutLimit = Duration(seconds: 15); | |
Future<http.Response> delete(Uri url, {Map<String, String>? headers, Object? body, Encoding? encoding}) { | |
return http.delete(url, headers: headers, body: body, encoding: encoding).timeout(timeOutLimit); | |
} | |
Future<http.Response> get(Uri url, {Map<String, String>? headers}) { | |
return http.get(url, headers: headers).timeout(timeOutLimit); | |
} | |
Future<http.Response> patch(Uri url, {Map<String, String>? headers, Object? body, Encoding? encoding}) { | |
return http.patch(url, headers: headers, body: body, encoding: encoding).timeout(timeOutLimit); | |
} | |
Future<http.Response> post(Uri url, {Map<String, String>? headers, Object? body, Encoding? encoding}) { | |
return http.post(url, headers: headers, body: body, encoding: encoding).timeout(timeOutLimit); | |
} | |
Future<http.Response> put(Uri url, {Map<String, String>? headers, Object? body, Encoding? encoding}) { | |
return http.put(url, headers: headers, body: body, encoding: encoding).timeout(timeOutLimit); | |
} | |
Future<Uint8List> readBytes(Uri url, {Map<String, String>? headers}) { | |
return http.readBytes(url, headers: headers).timeout(timeOutLimit); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment