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
9 changes: 4 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ name: CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

env:
DART_VERSION: 3.5.0
DART_VERSION: 3.10.4

jobs:
ci:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

Expand All @@ -42,7 +41,7 @@ jobs:
- uses: codecov/codecov-action@40a12dcee2df644d47232dde008099a3e9e4f865 #v3.1.2
with:
files: coverage/lcov.info

pana:
runs-on: ubuntu-latest
steps:
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,10 @@ build/
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3

# FVM Version Cache
.fvm/
# FVM Configuration
.fvmrc
# FVM Flutter SDK Configuration
.vscode/settings.json
30 changes: 22 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,64 @@
## 0.6.0

## Unreleased

- Removed `freezed` and `freezed_annotation` dependencies.
- Updated `NetworkRequestBody` and `SturdyHttpEvent` to be a sealed classes.
- Changed behavior of when `DecodingError`s are emitted.

## 0.5.1

## What's Changed
* fix: loosen collection constraint by @btrautmann in https://github.com/Betterment/sturdy_http/pull/16

- fix: loosen collection constraint by @btrautmann in https://github.com/Betterment/sturdy_http/pull/16

**Full Changelog**: https://github.com/Betterment/sturdy_http/compare/v0.5.0...v0.5.1

## 0.5.0

## What's Changed
* refactor: make network response a sealed class by @btrautmann in https://github.com/Betterment/sturdy_http/pull/14

- refactor: make network response a sealed class by @btrautmann in https://github.com/Betterment/sturdy_http/pull/14

**Full Changelog**: https://github.com/Betterment/sturdy_http/compare/v0.4.0...v0.5.0

## 0.4.0

## What's Changed
* feat: Add support for `426: Upgrade Required` by @willlockwood in https://github.com/Betterment/sturdy_http/pull/12

- feat: Add support for `426: Upgrade Required` by @willlockwood in https://github.com/Betterment/sturdy_http/pull/12

## New Contributors
* @willlockwood made their first contribution in https://github.com/Betterment/sturdy_http/pull/12

- @willlockwood made their first contribution in https://github.com/Betterment/sturdy_http/pull/12

**Full Changelog**: https://github.com/Betterment/sturdy_http/compare/v0.3.1...v0.4.0

## 0.3.1

## What's Changed
* fix: export retry_behavior by @btrautmann in https://github.com/Betterment/sturdy_http/pull/10

- fix: export retry_behavior by @btrautmann in https://github.com/Betterment/sturdy_http/pull/10

**Full Changelog**: https://github.com/Betterment/sturdy_http/compare/v0.3.0...v0.3.1

## 0.3.0

## What's Changed
* feat: support retrying failed requests by @btrautmann in https://github.com/Betterment/sturdy_http/pull/8

- feat: support retrying failed requests by @btrautmann in https://github.com/Betterment/sturdy_http/pull/8

**Full Changelog**: https://github.com/Betterment/sturdy_http/compare/v0.2.0...v0.3.0

## 0.2.0

## What's Changed
* chore: update outdated dependencies by @ClaireDavis in https://github.com/Betterment/sturdy_http/pull/6

- chore: update outdated dependencies by @ClaireDavis in https://github.com/Betterment/sturdy_http/pull/6

## New Contributors
* @ClaireDavis made their first contribution in https://github.com/Betterment/sturdy_http/pull/6

- @ClaireDavis made their first contribution in https://github.com/Betterment/sturdy_http/pull/6

**Full Changelog**: https://github.com/Betterment/sturdy_http/compare/v0.1.0...v0.2.0

Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ Then, execute requests:
Future<Result<MyData>> fetch({required int id}) async {
return _client.execute<Json, MyData>(
GetRequest('/v6/data/${id}'),
onResponse: (r) => r.maybeWhen(
ok: (json) => Result.success(MyData.fromJson),
orElse: () => Result.failure(r),
),
onResponse: (r) {
return switch (r) {
OkResponse(:final response) => Result.success(MyData.fromJson(response)),
_ => Result.failure(r),
};
},
);
}
```
Expand Down Expand Up @@ -69,9 +71,6 @@ extension SturdyHttpX on SturdyHttp {
}
```

> **Warning**
> We're considering open-sourcing our `Result` type and integrating it into `SturdyHttp`. If we did, we'd likely change `execute`'s return type to be a `Result`, and offer `executeUnsafe` as the non-`Result` (i.e `Exception` throwing) alternative. This would be a breaking change.

## Contributing

If you run into a bug or limitation when using `SturdyHttp`, we'd love your help in resolving it. First, it would be awesome if you could [open an issue](https://github.com/Betterment/sturdy_http/issues/new/choose) to discuss. If we feel like we should move forward with a change and you're willing to contribute, create a fork of `SturdyHttp` and open a PR against the main repo.
6 changes: 4 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
include: package:lints/recommended.yaml

formatter:
page_width: 80

linter:
rules:
- package_api_docs
Expand All @@ -15,5 +18,4 @@ analyzer:
missing_return: error
missing_required_param: error
exclude:
- "build/**"
- "**/*.g.dart"
- 'build/**'
21 changes: 0 additions & 21 deletions build.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions codecov.yml

This file was deleted.

29 changes: 12 additions & 17 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@ import 'package:sturdy_http/sturdy_http.dart';
void main(List<String> args) async {
// Set up some fake HTTP responses using Charlatan
final charlatan = Charlatan()
..whenGet(
'/foo',
(request) => CharlatanHttpResponse(
body: 'Hello World!',
),
)
..whenPost(
'/foo',
(request) => CharlatanHttpResponse(statusCode: 204),
);
..whenGet('/foo', (request) => CharlatanHttpResponse(body: 'Hello World!'))
..whenPost('/foo', (request) => CharlatanHttpResponse(statusCode: 204));

// Create your client
final client = SturdyHttp(
Expand All @@ -39,7 +31,7 @@ void main(List<String> args) async {
// 'mutative request success' <-- From ExampleEventListener
// 'success!'
await client.execute<void, void>(
PostRequest('/foo', data: NetworkRequestBody.empty()),
PostRequest('/foo', data: EmptyRequestBody()),
onResponse: (r) {
return switch (r) {
OkNoContent() => print('success!'),
Expand All @@ -51,11 +43,14 @@ void main(List<String> args) async {

class ExampleEventListener implements SturdyHttpEventListener {
@override
Future<void> onEvent(SturdyHttpEvent event) {
return event.when(
decodingError: (_, __, ___) async => print('decoding error'),
authFailure: (_) async => print('auth failure'),
mutativeRequestSuccess: (_) async => print('mutative request success'),
);
Future<void> onEvent(SturdyHttpEvent event) async {
switch (event) {
case DecodingError():
print('decoding error');
case AuthFailure():
print('auth failure');
case MutativeRequestSuccess():
print('mutative request success');
}
}
}
3 changes: 2 additions & 1 deletion lib/src/_dio_error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ extension DioExceptionX on DioException {
DioExceptionType.sendTimeout,
DioExceptionType.unknown,
];
final isKnownExceptionType = error is HandshakeException ||
final isKnownExceptionType =
error is HandshakeException ||
error is SocketException ||
error is HttpException;
return knownBadConnectionTypes.contains(type) || isKnownExceptionType;
Expand Down
22 changes: 5 additions & 17 deletions lib/src/deserializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ class BackgroundDeserializer implements Deserializer {
// Use BroadcastStream to facilitate multiple requests for
// deserialization over the same SendPort.
_results ??= _mainReceivePort.asBroadcastStream();
_workerIsolate ??= await _spawnIsolate(
mainReceivePort: _mainReceivePort,
);
_workerIsolate ??= await _spawnIsolate(mainReceivePort: _mainReceivePort);
_workerSendPort ??= await _results!.first as SendPort;
}
}
Expand Down Expand Up @@ -162,10 +160,8 @@ class _IsolateRequest {
final SendPort resultPort;
final dynamic Function() decoder;

_IsolateRequest({
required this.resultPort,
required this.decoder,
}) : id = const Uuid().v4();
_IsolateRequest({required this.resultPort, required this.decoder})
: id = const Uuid().v4();
}

/// The result of an attempt to deserialize a response.
Expand All @@ -184,16 +180,8 @@ class _IsolateResult {
});

factory _IsolateResult.ok(dynamic value, String requestId) =>
_IsolateResult._(
response: value,
error: null,
requestId: requestId,
);
_IsolateResult._(response: value, error: null, requestId: requestId);

factory _IsolateResult.error(Exception error, String requestId) =>
_IsolateResult._(
response: null,
error: error,
requestId: requestId,
);
_IsolateResult._(response: null, error: error, requestId: requestId);
}
Loading