Skip to content

Commit

Permalink
Allow const ctor (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath committed Apr 19, 2019
1 parent e8479e1 commit e6b0200
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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).

## [Unreleased]
### Added
- `JsonApiClient` has `const` constructor

## [1.0.1] - 2019-04-05
### Fixed
- Bumped the dependencies versions due to a bug in `json_api_document`.

## [1.0.1] - 2019-04-05
### Changed
Expand Down Expand Up @@ -61,7 +67,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Client: fetch resources, collections, related resources and relationships

[Unreleased]: https://github.com/f3ath/json-api-dart/compare/1.0.1...HEAD
[1.0.1]: https://github.com/f3ath/json-api-dart/compare/0.6.0...1.0.0
[1.0.1]: https://github.com/f3ath/json-api-dart/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/f3ath/json-api-dart/compare/0.6.0...1.0.0
[0.6.0]: https://github.com/f3ath/json-api-dart/compare/0.5.0...0.6.0
[0.5.0]: https://github.com/f3ath/json-api-dart/compare/0.4.0...0.5.0
Expand Down
10 changes: 6 additions & 4 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:async';
import 'dart:convert';

import 'package:http/http.dart' as http;
import 'package:json_api/src/nullable.dart';
import 'package:json_api/src/response.dart';
import 'package:json_api/src/status_code.dart';
import 'package:json_api/src/nullable.dart';
import 'package:json_api_document/json_api_document.dart';
import 'package:json_api_document/parser.dart';

Expand All @@ -16,14 +16,14 @@ typedef http.Client HttpClientFactory();
class JsonApiClient {
static const contentType = 'application/vnd.api+json';

JsonApiParser _parser = const JsonApiParser();
final JsonApiParser _parser = const JsonApiParser();

final HttpClientFactory _factory;

/// JSON:API client uses Dart's native Http Client internally.
/// To customize its behavior you can pass the [factory] function.
JsonApiClient({HttpClientFactory factory})
: _factory = factory ?? (() => http.Client());
const JsonApiClient({HttpClientFactory factory})
: _factory = factory ?? _defaultFactory;

/// Fetches a resource collection by sending a GET request to the [uri].
/// Use [headers] to pass extra HTTP headers.
Expand Down Expand Up @@ -194,3 +194,5 @@ class JsonApiClient {
}
}
}

http.Client _defaultFactory() => http.Client();
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies:
collection: "^1.14.11"
http: "^0.12.0"
dev_dependencies:
json_api_server: "^0.0.1"
json_api_server: "0.0.2"
json_matcher: "^0.2.3"
stream_channel: "^1.6.8"
test: "^1.6.1"
Expand Down

0 comments on commit e6b0200

Please sign in to comment.