Skip to content

Commit 8695d7d

Browse files
authored
v5.4.0 (#132)
1 parent 0254cb1 commit 8695d7d

20 files changed

+48
-211
lines changed

.github/workflows/dart.yml

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
- uses: actions/checkout@v2
1919
- name: Install dependencies
2020
run: dart pub get
21+
- name: Print Dart version
22+
run: dart --version
2123
- name: Format
2224
run: dart format --output none --set-exit-if-changed example lib test
2325
- name: Analyzer

CHANGELOG.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [5.4.0] - 2023-04-30
8+
### Changed
9+
- Switch to http\_interop packages.
10+
- Bump min SDK version to 2.19.
11+
712
## [5.3.0] - 2022-12-29
813
### Added
914
- Client MessageConverter class to control HTTP request/response conversion.
@@ -46,7 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4651
- Sound null-safety support.
4752

4853
### Changed
49-
- Everything. Again. This is another major **BC-breaking** rework. Please refer to
54+
- Everything. Again. This is another major **BC-breaking** rework. Please refer to
5055
the API documentation, examples and tests.
5156

5257
## [3.2.3] - 2020-08-06
@@ -87,11 +92,11 @@ is missing. Before in such cases a `FormatException` would be thrown ([pr](https
8792

8893
## [3.2.2] - 2020-01-07
8994
### Fixed
90-
- Can not decode related resource which is null ([\#77](https://github.com/f3ath/json-api-dart/issues/77))
95+
- Can not decode related resource which is null ([\#77](https://github.com/f3ath/json-api-dart/issues/77))
9196

9297
## [3.2.1] - 2020-01-01
9398
### Fixed
94-
- Incorrect URL in the example in the Client documentation ([\#74](https://github.com/f3ath/json-api-dart/issues/74))
99+
- Incorrect URL in the example in the Client documentation ([\#74](https://github.com/f3ath/json-api-dart/issues/74))
95100

96101
## [3.2.0] - 2019-12-30
97102
### Added
@@ -157,14 +162,14 @@ is missing. Before in such cases a `FormatException` would be thrown ([pr](https
157162

158163
## [2.0.0] - 2019-07-12
159164
### Changed
160-
- This package now consolidates the Client, the Server and the Document in one single library.
161-
It does not depend on `json_api_document` and `json_api_server` anymore, please remove these packages
165+
- This package now consolidates the Client, the Server and the Document in one single library.
166+
It does not depend on `json_api_document` and `json_api_server` anymore, please remove these packages
162167
from your `pubspec.yaml`.
163168
- The min Dart SDK version bumped to `2.3.0`
164169
- The Client requires an instance of HttpClient to be passed to the constructor explicitly.
165-
- Both the Document and the Server have been refactored with lots of **BREAKING CHANGES**.
170+
- Both the Document and the Server have been refactored with lots of **BREAKING CHANGES**.
166171
See the examples and the functional tests for details.
167-
- Meta properties are not defensively copied, but set directly. Meta property behavior is unified across
172+
- Meta properties are not defensively copied, but set directly. Meta property behavior is unified across
168173
the Document model.
169174

170175
### Removed
@@ -224,6 +229,7 @@ the Document model.
224229
### Added
225230
- Client: fetch resources, collections, related resources and relationships
226231

232+
[5.4.0]: https://github.com/f3ath/json-api-dart/compare/5.3.0...5.4.0
227233
[5.3.0]: https://github.com/f3ath/json-api-dart/compare/5.2.0...5.3.0
228234
[5.2.0]: https://github.com/f3ath/json-api-dart/compare/5.1.0...5.2.0
229235
[5.1.0]: https://github.com/f3ath/json-api-dart/compare/5.0.5...5.1.0

example/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The client and server examples are meant to run together.
1+
The client and server examples are meant to run together.
22

33
- Open a new terminal window and run `dart server.dart`
44
- While the server is running, open another window and run `dart client.dart`

example/server/json_api_server.dart

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import 'dart:convert';
21
import 'dart:io';
32

3+
import 'package:http_interop_io/http_interop_io.dart';
44
import 'package:json_api/http.dart';
55

66
class JsonApiServer {
@@ -41,18 +41,7 @@ class JsonApiServer {
4141

4242
Future<HttpServer> _createServer() async {
4343
final server = await HttpServer.bind(host, port);
44-
server.listen((request) async {
45-
final headers = <String, String>{};
46-
request.headers.forEach((k, v) => headers[k] = v.join(','));
47-
final response = await _handler.handle(HttpRequest(
48-
request.method, request.requestedUri,
49-
body: await request.cast<List<int>>().transform(utf8.decoder).join())
50-
..headers.addAll(headers));
51-
response.headers.forEach(request.response.headers.add);
52-
request.response.statusCode = response.statusCode;
53-
request.response.write(response.body);
54-
await request.response.close();
55-
});
44+
server.listen(listener(_handler));
5645
return server;
5746
}
5847
}

lib/client.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
/// The [RoutingClient] should be your default choice.
2424
library client;
2525

26+
export 'package:http_interop_http/http_interop_http.dart';
2627
export 'package:json_api/src/client/client.dart';
27-
export 'package:json_api/src/client/disposable_handler.dart';
28-
export 'package:json_api/src/client/message_converter.dart';
2928
export 'package:json_api/src/client/persistent_handler.dart';
3029
export 'package:json_api/src/client/request.dart';
3130
export 'package:json_api/src/client/response/collection_fetched.dart';

lib/http.dart

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
/// This is a thin HTTP layer abstraction used by the client and the server
22
library http;
33

4-
export 'package:json_api/src/http/http_handler.dart';
5-
export 'package:json_api/src/http/http_headers.dart';
6-
export 'package:json_api/src/http/http_message.dart';
7-
export 'package:json_api/src/http/http_request.dart';
8-
export 'package:json_api/src/http/http_response.dart';
9-
export 'package:json_api/src/http/logging_handler.dart';
4+
export 'package:http_interop/http_interop.dart'
5+
show
6+
HttpMessage,
7+
HttpHeaders,
8+
HttpRequest,
9+
HttpResponse,
10+
HttpHandler,
11+
LoggingHandler;
12+
export 'package:json_api/src/http/http_response_ext.dart';
1013
export 'package:json_api/src/http/media_type.dart';
1114
export 'package:json_api/src/http/payload_codec.dart';
1215
export 'package:json_api/src/http/status_code.dart';

lib/src/client/client.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import 'package:http_interop_http/http_interop_http.dart';
12
import 'package:json_api/http.dart';
2-
import 'package:json_api/src/client/disposable_handler.dart';
33
import 'package:json_api/src/client/request.dart';
44
import 'package:json_api/src/client/response.dart';
55

lib/src/client/disposable_handler.dart

-19
This file was deleted.

lib/src/client/message_converter.dart

-67
This file was deleted.
+6-16
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
import 'dart:convert';
22

33
import 'package:http/http.dart';
4-
import 'package:json_api/http.dart';
5-
import 'package:json_api/src/client/message_converter.dart';
4+
import 'package:http_interop_http/http_interop_http.dart';
65

76
/// Handler which relies on the built-in Dart HTTP client.
87
/// It is the developer's responsibility to instantiate the client and
98
/// call `close()` on it in the end pf the application lifecycle.
10-
class PersistentHandler implements HttpHandler {
9+
class PersistentHandler extends HandlerWrapper {
1110
/// Creates a new instance of the handler. Do not forget to call `close()` on
1211
/// the [client] when it's not longer needed.
1312
///
1413
/// Use [messageConverter] to fine tune the HTTP request/response conversion.
1514
PersistentHandler(
16-
this.client,
15+
Client client,
1716
{@Deprecated('Deprecated in favor of MessageConverter.'
1817
' To be removed in version 6.0.0')
1918
this.defaultEncoding = utf8,
2019
MessageConverter? messageConverter})
21-
: _converter = messageConverter ??
22-
MessageConverter(defaultResponseEncoding: defaultEncoding);
20+
: super(client,
21+
messageConverter: messageConverter ??
22+
MessageConverter(defaultResponseEncoding: defaultEncoding));
2323

24-
final Client client;
2524
final Encoding defaultEncoding;
26-
final MessageConverter _converter;
27-
28-
@override
29-
Future<HttpResponse> handle(HttpRequest request) async {
30-
final convertedRequest = _converter.request(request);
31-
final streamedResponse = await client.send(convertedRequest);
32-
final response = await Response.fromStream(streamedResponse);
33-
return _converter.response(response);
34-
}
3525
}

lib/src/client/routing_client.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:json_api/document.dart';
2+
import 'package:json_api/http.dart';
23
import 'package:json_api/routing.dart';
34
import 'package:json_api/src/client/client.dart';
45
import 'package:json_api/src/client/request.dart';

lib/src/http/http_handler.dart

-6
This file was deleted.

lib/src/http/http_headers.dart

-8
This file was deleted.

lib/src/http/http_message.dart

-9
This file was deleted.

lib/src/http/http_request.dart

-24
This file was deleted.

lib/src/http/http_response.dart renamed to lib/src/http/http_response_ext.dart

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import 'package:json_api/src/http/http_message.dart';
1+
import 'package:http_interop/http_interop.dart' as interop;
22
import 'package:json_api/src/http/media_type.dart';
33
import 'package:json_api/src/http/status_code.dart';
44

55
/// The response sent by the server and received by the client
6-
class HttpResponse extends HttpMessage {
7-
HttpResponse(this.statusCode, {String body = ''}) : super(body);
8-
9-
/// Response status code
10-
final int statusCode;
11-
6+
extension HttpResponseExt on interop.HttpResponse {
127
/// True if the body is not empty and the Content-Type
138
/// is `application/vnd.api+json`
149
bool get hasDocument =>

lib/src/http/logging_handler.dart

-20
This file was deleted.

lib/src/http/payload_codec.dart

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import 'dart:async';
22
import 'dart:convert';
33

44
/// Encodes/decodes JSON payload.
5-
///
6-
/// The methods are designed to be asynchronous to allow for conversion to be
7-
/// performed in isolates if needed.
85
class PayloadCodec {
96
const PayloadCodec();
107

0 commit comments

Comments
 (0)