-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from thongdn-it/isolate_http
[isolate_http] Publish v2.2.0
- Loading branch information
Showing
8 changed files
with
150 additions
and
36 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
# [2.2.0] - 13/06/2022 | ||
|
||
- Add log CURL. | ||
- Add `contentLength` for IsolateHttpRequest, IsolateHttpResponse. | ||
|
||
# [2.1.1] - 23/09/2021 | ||
|
||
* [Fix] missing `content-type` header in post method. | ||
- [Fix] missing `content-type` header in post method. | ||
|
||
# [2.1.0] - 12/09/2021 | ||
|
||
* Support timeout, debug label. | ||
- Support timeout, debug label. | ||
|
||
# [2.0.0] - 03/09/2021 | ||
|
||
* Support null-safety. | ||
- Support null-safety. | ||
|
||
# [1.0.0] - 01/09/2021 | ||
|
||
* Initial package. | ||
- Initial package. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,19 @@ IsolateHttp provides a way to launch [http package][http_pub_url] with [IsolateF | |
Performing a `GET` request: | ||
|
||
```dart | ||
final _response = await IsolateHttp().get('https://example.com/product', | ||
final _isolateHttp = IsolateHttp(); | ||
``` | ||
|
||
```dart | ||
final _response = await _isolateHttp.get('https://example.com/product', | ||
headers: {'Authorization': 'abc='}); | ||
print(_response); | ||
``` | ||
|
||
Performing a `POST` request: | ||
|
||
```dart | ||
final _response = await IsolateHttp().post('https://example.com/product', | ||
final _response = await _isolateHttp.post('https://example.com/product', | ||
headers: {'Authorization': 'abc='}, | ||
body: {'size': 'XL', 'price': 236}, | ||
files: [ | ||
|
@@ -29,19 +33,29 @@ print(_response); | |
Performing a `DELETE` request: | ||
|
||
```dart | ||
final _response = await IsolateHttp().delete('https://example.com/product/1', | ||
final _response = await _isolateHttp.delete('https://example.com/product/1', | ||
headers: {'Authorization': 'abc='}); | ||
print(_response); | ||
``` | ||
|
||
*** You can set a timeout and debug label for your request when creating an IsolateHttp like: | ||
\*\*\* You can set a timeout and debug label for your request when creating an IsolateHttp like: | ||
|
||
```dart | ||
IsolateHttp(timeout: Duration(seconds: 30), debugLabel: 'get_products') | ||
final _isolateHttp = IsolateHttp(timeout: Duration(seconds: 30), debugLabel: 'get_products') | ||
``` | ||
|
||
If timeout, its returns you an IsolateHttpResponse with status code 408 (Request Timeout). | ||
|
||
### Log Curl | ||
|
||
```dart | ||
_isolateHttp.listener = (curl) { | ||
if (kDebugMode) { | ||
log('Isolate Http -> Curl: ----------------\n$curl\n----------------'); | ||
} | ||
}; | ||
``` | ||
|
||
## Author | ||
|
||
IsolateHttp is developed by Thong Dang. You can contact me at [email protected] | ||
|
@@ -50,8 +64,7 @@ If you like my project, you can support me [![Buy Me A Coffee][buy_me_a_coffee_i | |
|
||
Thank you! ❤️ | ||
|
||
[//]: # (reference links) | ||
|
||
[//]: # 'reference links' | ||
[http_pub_url]: https://pub.dev/packages/http | ||
[isolate_flutter_pub_url]: https://pub.dev/packages/isolate_flutter | ||
[pub_url]: https://pub.dev/packages/isolate_http | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
import 'dart:developer'; | ||
import 'package:flutter/foundation.dart'; | ||
|
||
import 'package:isolate_http/isolate_http.dart'; | ||
|
||
void main(List<String> args) async { | ||
// https://developers.google.com/books | ||
final _response = await IsolateHttp( | ||
timeout: Duration(seconds: 60), debugLabel: 'search_book') | ||
.get('https://www.googleapis.com/auth/books/v1/volumes', | ||
query: {'q': 'flutter'}); | ||
final _isolateHttp = | ||
IsolateHttp(timeout: Duration(seconds: 60), debugLabel: 'search_book'); | ||
final _response = await _isolateHttp.get( | ||
'https://www.googleapis.com/auth/books/v1/volumes', | ||
query: {'q': 'flutter'}); | ||
if (_response?.statusCode == 200) { | ||
final _bodyJson = _response?.bodyJson; | ||
print(_bodyJson); | ||
} else { | ||
print('Request failed with status: ${_response?.statusCode}.'); | ||
} | ||
|
||
// Log Curl | ||
_isolateHttp.listener = (curl) { | ||
if (kDebugMode) { | ||
log('Isolate Http -> Curl: ----------------\n$curl\n----------------'); | ||
} | ||
}; | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:http/http.dart'; | ||
|
||
abstract class LogUtils { | ||
static String getCurl(BaseRequest request) { | ||
List<String> components = ['curl -i']; | ||
if (request.method.toUpperCase() != 'GET') { | ||
components.add('-X ${request.method.toUpperCase()}'); | ||
} | ||
|
||
for (var _key in request.headers.keys) { | ||
if (_key != 'Cookie') { | ||
components.add('-H "$_key: ${request.headers[_key]}"'); | ||
} | ||
} | ||
|
||
if (request is Request) { | ||
if (request.body.isNotEmpty == true) { | ||
final data = request.body.replaceAll('"', '\\"'); | ||
components.add('-d "$data"'); | ||
} | ||
} else if (request is MultipartRequest) { | ||
if (request.fields.isNotEmpty == true) { | ||
final data = jsonEncode(request.fields).replaceAll('"', '\\"'); | ||
components.add('-d "$data"'); | ||
} | ||
if (request.files.isNotEmpty == true) { | ||
for (var _file in request.files) { | ||
components.add('-F ${_file.field}=@/path/to/${_file.filename}'); | ||
} | ||
} | ||
} | ||
|
||
components.add('"${request.url.toString()}"'); | ||
|
||
return components.join(' \\\n\t'); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
name: isolate_http | ||
description: IsolateHttp provides a way to launch 'http' library in Isolate with IsolatesFlutter. | ||
version: 2.1.1 | ||
description: IsolateHttp provides a way to launch 'http' library in Isolate with IsolatesFlutter. | ||
version: 2.2.0 | ||
homepage: https://github.com/thongdn-it/isolate_flutter/tree/master/isolate_http | ||
repository: https://github.com/thongdn-it/isolate_flutter/tree/master/isolate_http | ||
|
||
environment: | ||
sdk: ">=2.12.0 <3.0.0" | ||
sdk: '>=2.12.0 <3.0.0' | ||
|
||
dependencies: | ||
flutter: | ||
sdk: flutter | ||
|
||
isolate_flutter: ^2.0.0 | ||
http: ^0.13.0 | ||
http_parser: ^4.0.0 | ||
|
||
dev_dependencies: | ||
lints: ^1.0.1 | ||
lints: ^1.0.1 |