https://github.com/0xdir/connection_dart
An opinionated wrapper around the revered http package, where http responses are objects for easy parsing and error handling.
https://github.com/0xdir/connection_dart
api-rest dart https tooling
Last synced: 10 months ago
JSON representation
An opinionated wrapper around the revered http package, where http responses are objects for easy parsing and error handling.
- Host: GitHub
- URL: https://github.com/0xdir/connection_dart
- Owner: 0xdir
- License: mit
- Created: 2023-07-08T11:21:23.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-07-09T02:59:48.000Z (over 2 years ago)
- Last Synced: 2025-01-14T11:57:21.706Z (12 months ago)
- Topics: api-rest, dart, https, tooling
- Language: Dart
- Homepage: https://pub.dev/packages/connection
- Size: 5.86 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
[](https://pub.dev/packages/connection)
[](https://pub.dev/packages/connection/publisher)
An opinionated wrapper around the revered http package, where HTTP responses are objects
for easy parsing and error handling.
## Using
The easiest way to use this library is via the top-level ```Connection``` class.
```dart
import 'package:connection/connection.dart';
void main() async {
/// Initialize the main object
Connection connection = Connection(
authority: 'swapi.dev',
defaultHeaders: {'Content-Type': 'application/json'},
);
try {
/// Call the endpoint
Response response = await connection.get(
endpoint: '/api/people/1',
);
if (response.statusCode == 200) {
/// Do stuff with the response
print(response.statusCode);
print(json.decode(response.body));
} else {
/// Handle the server error
print('Server Error: ${response.statusCode}:');
print(response.body);
}
} catch (e) {
/// Throws an exception if an unknown error occurs
print(e);
}
/// Close the connection
connection.close();
}
```
## Supported calls
Implemented:
1. https
2. default and custom headers
3. GET with query params
4. POST with payload
Not implemented:
1. everything else
If more features are needed, feel free to open a discussion on github.
## Getting Help
Submit an issue on [github].
[github]: https://github.com/0xdir/connection_dart
## How to contribute
All feedback and suggestions for improvements are welcome:
1. Open a discussion on [github]
2. Discuss proposed changes
3. Submit a PR (optional)
[github]: https://github.com/0xdir/connection_dart
## Support my work
This package is possible thanks to the people and companies
who donate money, services or time to keep the project running.
If you're interested in becoming a Sponsor, Backer or Contributor
to expand the project, reach out to me on [github].
[github]: https://github.com/sponsors/0xdir
Or buy me coffee at `0xdir.near`.