Skip to content

v5.4.0 #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 1, 2023
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
2 changes: 2 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:
- uses: actions/checkout@v2
- name: Install dependencies
run: dart pub get
- name: Print Dart version
run: dart --version
- name: Format
run: dart format --output none --set-exit-if-changed example lib test
- name: Analyzer
Expand Down
20 changes: 13 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.4.0] - 2023-04-30
### Changed
- Switch to http\_interop packages.
- Bump min SDK version to 2.19.

## [5.3.0] - 2022-12-29
### Added
- Client MessageConverter class to control HTTP request/response conversion.
Expand Down Expand Up @@ -46,7 +51,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Sound null-safety support.

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

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

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

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

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

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

### Removed
Expand Down Expand Up @@ -224,6 +229,7 @@ the Document model.
### Added
- Client: fetch resources, collections, related resources and relationships

[5.4.0]: https://github.com/f3ath/json-api-dart/compare/5.3.0...5.4.0
[5.3.0]: https://github.com/f3ath/json-api-dart/compare/5.2.0...5.3.0
[5.2.0]: https://github.com/f3ath/json-api-dart/compare/5.1.0...5.2.0
[5.1.0]: https://github.com/f3ath/json-api-dart/compare/5.0.5...5.1.0
Expand Down
2 changes: 1 addition & 1 deletion example/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The client and server examples are meant to run together.
The client and server examples are meant to run together.

- Open a new terminal window and run `dart server.dart`
- While the server is running, open another window and run `dart client.dart`
15 changes: 2 additions & 13 deletions example/server/json_api_server.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';
import 'dart:io';

import 'package:http_interop_io/http_interop_io.dart';
import 'package:json_api/http.dart';

class JsonApiServer {
Expand Down Expand Up @@ -41,18 +41,7 @@ class JsonApiServer {

Future<HttpServer> _createServer() async {
final server = await HttpServer.bind(host, port);
server.listen((request) async {
final headers = <String, String>{};
request.headers.forEach((k, v) => headers[k] = v.join(','));
final response = await _handler.handle(HttpRequest(
request.method, request.requestedUri,
body: await request.cast<List<int>>().transform(utf8.decoder).join())
..headers.addAll(headers));
response.headers.forEach(request.response.headers.add);
request.response.statusCode = response.statusCode;
request.response.write(response.body);
await request.response.close();
});
server.listen(listener(_handler));
return server;
}
}
3 changes: 1 addition & 2 deletions lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
/// The [RoutingClient] should be your default choice.
library client;

export 'package:http_interop_http/http_interop_http.dart';
export 'package:json_api/src/client/client.dart';
export 'package:json_api/src/client/disposable_handler.dart';
export 'package:json_api/src/client/message_converter.dart';
export 'package:json_api/src/client/persistent_handler.dart';
export 'package:json_api/src/client/request.dart';
export 'package:json_api/src/client/response/collection_fetched.dart';
Expand Down
15 changes: 9 additions & 6 deletions lib/http.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/// This is a thin HTTP layer abstraction used by the client and the server
library http;

export 'package:json_api/src/http/http_handler.dart';
export 'package:json_api/src/http/http_headers.dart';
export 'package:json_api/src/http/http_message.dart';
export 'package:json_api/src/http/http_request.dart';
export 'package:json_api/src/http/http_response.dart';
export 'package:json_api/src/http/logging_handler.dart';
export 'package:http_interop/http_interop.dart'
show
HttpMessage,
HttpHeaders,
HttpRequest,
HttpResponse,
HttpHandler,
LoggingHandler;
export 'package:json_api/src/http/http_response_ext.dart';
export 'package:json_api/src/http/media_type.dart';
export 'package:json_api/src/http/payload_codec.dart';
export 'package:json_api/src/http/status_code.dart';
2 changes: 1 addition & 1 deletion lib/src/client/client.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:http_interop_http/http_interop_http.dart';
import 'package:json_api/http.dart';
import 'package:json_api/src/client/disposable_handler.dart';
import 'package:json_api/src/client/request.dart';
import 'package:json_api/src/client/response.dart';

Expand Down
19 changes: 0 additions & 19 deletions lib/src/client/disposable_handler.dart

This file was deleted.

67 changes: 0 additions & 67 deletions lib/src/client/message_converter.dart

This file was deleted.

22 changes: 6 additions & 16 deletions lib/src/client/persistent_handler.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
import 'dart:convert';

import 'package:http/http.dart';
import 'package:json_api/http.dart';
import 'package:json_api/src/client/message_converter.dart';
import 'package:http_interop_http/http_interop_http.dart';

/// Handler which relies on the built-in Dart HTTP client.
/// It is the developer's responsibility to instantiate the client and
/// call `close()` on it in the end pf the application lifecycle.
class PersistentHandler implements HttpHandler {
class PersistentHandler extends HandlerWrapper {
/// Creates a new instance of the handler. Do not forget to call `close()` on
/// the [client] when it's not longer needed.
///
/// Use [messageConverter] to fine tune the HTTP request/response conversion.
PersistentHandler(
this.client,
Client client,
{@Deprecated('Deprecated in favor of MessageConverter.'
' To be removed in version 6.0.0')
this.defaultEncoding = utf8,
MessageConverter? messageConverter})
: _converter = messageConverter ??
MessageConverter(defaultResponseEncoding: defaultEncoding);
: super(client,
messageConverter: messageConverter ??
MessageConverter(defaultResponseEncoding: defaultEncoding));

final Client client;
final Encoding defaultEncoding;
final MessageConverter _converter;

@override
Future<HttpResponse> handle(HttpRequest request) async {
final convertedRequest = _converter.request(request);
final streamedResponse = await client.send(convertedRequest);
final response = await Response.fromStream(streamedResponse);
return _converter.response(response);
}
}
1 change: 1 addition & 0 deletions lib/src/client/routing_client.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:json_api/document.dart';
import 'package:json_api/http.dart';
import 'package:json_api/routing.dart';
import 'package:json_api/src/client/client.dart';
import 'package:json_api/src/client/request.dart';
Expand Down
6 changes: 0 additions & 6 deletions lib/src/http/http_handler.dart

This file was deleted.

8 changes: 0 additions & 8 deletions lib/src/http/http_headers.dart

This file was deleted.

9 changes: 0 additions & 9 deletions lib/src/http/http_message.dart

This file was deleted.

24 changes: 0 additions & 24 deletions lib/src/http/http_request.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import 'package:json_api/src/http/http_message.dart';
import 'package:http_interop/http_interop.dart' as interop;
import 'package:json_api/src/http/media_type.dart';
import 'package:json_api/src/http/status_code.dart';

/// The response sent by the server and received by the client
class HttpResponse extends HttpMessage {
HttpResponse(this.statusCode, {String body = ''}) : super(body);

/// Response status code
final int statusCode;

extension HttpResponseExt on interop.HttpResponse {
/// True if the body is not empty and the Content-Type
/// is `application/vnd.api+json`
bool get hasDocument =>
Expand Down
20 changes: 0 additions & 20 deletions lib/src/http/logging_handler.dart

This file was deleted.

3 changes: 0 additions & 3 deletions lib/src/http/payload_codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import 'dart:async';
import 'dart:convert';

/// Encodes/decodes JSON payload.
///
/// The methods are designed to be asynchronous to allow for conversion to be
/// performed in isolates if needed.
class PayloadCodec {
const PayloadCodec();

Expand Down
Loading