Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .flutter-plugins-dependencies

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.0.0
- **Nested JSON Key Extraction**: Added `dataKey` parameter to all network requests to extract nested JSON values before parsing.
- **Item-Level Nested Key Extraction**: Added `itemDataKey` to all list-returning requests (`getList`, `postList`, etc.) to unwrap each list item (e.g., `itemDataKey: 'attributes'`) before passing it to the mapper.
- **Smart Request Cancellation Manager**: Added `cancelTag` parameter to manage and cancel multiple requests at once with automatic `cancelOld` support.
- **Mapping Cancellation**: Better support for canceling requests during JSON mapping in isolates. Now, when a request is canceled, the mapping process is also canceled to save resources and improve performance.

## 0.6.0
- Updated dependencies to their latest versions.
- PATCH Request Support: Added new methods (patch and patchList) to easily perform PATCH API requests.
Expand Down
47 changes: 42 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Wrapper around [`Dio`](https://pub.dev/packages/dio) that can perform API requests with better error handling and easily get the result of any API request.

## Features
- Perform GET, POST, PUT,, and DELETE HTTP methods for retrieving from and sending data to a server.
- Perform GET, POST, PUT, PATCH, and DELETE HTTP methods for retrieving from and sending data to a server.
- Better Error handling for API and [`Dio`](https://pub.dev/packages/dio) Errors with the ability to customize these errors.
- Each request is wrapped by `NetworkResult` which returns whether success or failure of the API request.
- No need to use try catch anymore as every request is handled.
Expand All @@ -14,13 +14,12 @@ Wrapper around [`Dio`](https://pub.dev/packages/dio) that can perform API reques

In `pubspec.yaml` add these lines to `dependencies`

```yaml
playx_network: ^0.6.0
playx_network: ^0.7.0
```

## Usage

We can use `PlayxNetworkClient` to perform GET, POST, PUT,, and DELETE HTTP methods for retrieving from and sending data to a server.
We can use `PlayxNetworkClient` to perform GET, POST, PUT, PATCH, and DELETE HTTP methods for retrieving from and sending data to a server.

To use it we need to :

Expand All @@ -33,7 +32,7 @@ To use it we need to :
BaseOptions(
baseUrl: _baseUrl,
connectTimeout: const Duration(seconds: 20),
senTimeout: const Duration(seconds: 20),
sendTimeout: const Duration(seconds: 20),
),
),
//If you want to attach a token to the client or add any custom headers to all requests.
Expand Down Expand Up @@ -125,6 +124,44 @@ Here is all available methods of `PlayxNetworkClient` :
| putList<T> | sends a `PUT` request to the given url and returns `NetworkResult` of List of Type [T] model. |
| delete<T> | sends a `DELETE` request to the given url and returns `NetworkResult` of Type [T] model.|
| deleteList<T> | sends a `DELETE` request to the given url and returns `NetworkResult` of List of Type [T] model. |
| patch<T> | sends a `PATCH` request to the given url and returns `NetworkResult` of Type [T] model.|
| patchList<T> | sends a `PATCH` request to the given url and returns `NetworkResult` of List of Type [T] model. |

## Nested JSON Key Extraction
You can extract nested JSON values directly from the response before parsing using dot-notation with the `dataKey` parameter.
This is useful when you want to target a specific field in a large JSON structure without mapping the outer layers.

```dart
final result = await _client.get(
'forecast',
query: {
'latitude': '30.04',
'longitude': '31.23',
'current_weather': 'true',
},
// Extract 'current_weather' directly from the response
dataKey: 'current_weather',
fromJson: CurrentWeather.fromJson,
);
```

## Smart Request Cancellation
Manage and cancel multiple requests easily using `cancelTag`.
By default, providing a `cancelTag` will automatically cancel any previous pending requests with the same tag (`cancelOld: true`).

```dart
// Subsequent calls with the same tag will cancel previous ones automatically
networkClient.getList(
'/search?q=query',
cancelTag: 'search_request',
fromJson: Cat.fromJson,
);

// You can also cancel requests manually
networkClient.cancelRequestsByTag('search_request');
```

Additionally, if a request is canceled while JSON mapping is occurring in an isolate, the mapping process itself is also terminated to save resources.


## Error Message customization:
Expand Down
2 changes: 2 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
Expand Down
6 changes: 6 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This an example that demonstrates how to use `playx_network` package to perform api requests.

It includes examples for:
- Basic GET and getList requests.
- **Nested JSON Extraction**: Using `dataKey` to parse specific fields from response.
- **Smart Request Cancellation**: Using `cancelTag` for managing concurrent requests.
- **Isolate Mapping Cancellation**: Automatic termination of JSON parsing when a request is canceled.

## Getting Started

A few resources to get you started if this is your first Flutter project:
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>12.0</string>
<string>13.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'
# platform :ios, '13.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Expand Down
37 changes: 37 additions & 0 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
PODS:
- Flutter (1.0.0)
- flutter_secure_storage_darwin (10.0.0):
- Flutter
- FlutterMacOS
- path_provider_foundation (0.0.1):
- Flutter
- FlutterMacOS
- shared_preferences_foundation (0.0.1):
- Flutter
- FlutterMacOS

DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_secure_storage_darwin (from `.symlinks/plugins/flutter_secure_storage_darwin/darwin`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)

EXTERNAL SOURCES:
Flutter:
:path: Flutter
flutter_secure_storage_darwin:
:path: ".symlinks/plugins/flutter_secure_storage_darwin/darwin"
path_provider_foundation:
:path: ".symlinks/plugins/path_provider_foundation/darwin"
shared_preferences_foundation:
:path: ".symlinks/plugins/shared_preferences_foundation/darwin"

SPEC CHECKSUMS:
Flutter: cabc95a1d2626b1b06e7179b784ebcf0c0cde467
flutter_secure_storage_darwin: acdb3f316ed05a3e68f856e0353b133eec373a23
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7

PODFILE CHECKSUM: 3c63482e143d1b91d2d2560aee9fb04ecc74ac7e

COCOAPODS: 1.16.2
Loading
Loading