https://github.com/rexios80/dio_response_validator
An extension on Dio response futures to perform validation and data transformation
https://github.com/rexios80/dio_response_validator
Last synced: 2 months ago
JSON representation
An extension on Dio response futures to perform validation and data transformation
- Host: GitHub
- URL: https://github.com/rexios80/dio_response_validator
- Owner: Rexios80
- License: bsd-3-clause
- Created: 2022-09-07T16:28:54.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-06-08T16:52:07.000Z (12 months ago)
- Last Synced: 2025-02-08T05:16:25.466Z (4 months ago)
- Language: Dart
- Homepage: https://pub.dev/packages/dio_response_validator
- Size: 42 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
An extension on Dio response futures to perform validation and data transformation
## Features
- Validate responses from Dio without using try/catch blocks everywhere
- Easily transform responses from Dio into your own data models
- Handles transformation errors## Usage
```dart
import 'package:dio/dio.dart';
import 'package:dio_response_validator/dio_response_validator.dart';void main() async {
final dio = Dio();final successResponse =
await dio.get('https://vrchat.com/api/1/config').validate(
transform: (data) => data['apiKey'],
);// Prints the api key
printResponse(successResponse);final failureResponse =
await dio.get('https://vrchat.com/api/2/config').validate();// Prints a 404 error
printResponse(failureResponse);
}void printResponse(ValidatedResponse response) {
if (response.succeeded) {
print(response.success!.data);
} else {
print(response.failure!);
}
}```
## Additional information
Pull requests welcome