Skip to content

Commit 96bf564

Browse files
authored
Update resources and relationships (#29)
1 parent cc66b3c commit 96bf564

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1563
-1185
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ 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

77
## [Unreleased]
8+
## [0.3.0] - 2019-03-16
9+
### Changed
10+
- Huge BC-breaking refactoring in the Document model which propagated everywhere
11+
812
### Added
913
- Resource attributes update
14+
- Resource relationships update
1015

1116
## [0.2.0] - 2019-03-01
1217
### Added
@@ -18,5 +23,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1823
### Added
1924
- Client: fetch resources, collections, related resources and relationships
2025

21-
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/0.2.0...HEAD
26+
[Unreleased]: https://github.com/f3ath/json-api-dart/compare/0.3.0...HEAD
27+
[0.3.0]: https://github.com/f3ath/json-api-dart/compare/0.2.0...0.3.0
2228
[0.2.0]: https://github.com/f3ath/json-api-dart/compare/0.1.0...0.2.0

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,49 @@
11
# Implementation of [JSON:API v1.0](http://jsonapi.org) in Dart
22

3+
## Warning! This is a work-in-progress. While at v0, the API is changing rapidly.
4+
35
### Feature roadmap
6+
The features here are roughly ordered by priority. Feel free to open an issue if you want to add another feature.
7+
48
#### Client
59
- [x] Fetching single resources and resource collections
10+
- [x] Collection pagination
611
- [x] Fetching relationships and related resources and collections
712
- [x] Fetching single resources
813
- [x] Creating resources
914
- [x] Deleting resources
1015
- [x] Updating resource's attributes
1116
- [x] Updating resource's relationships
12-
- [ ] Updating relationships
17+
- [x] Updating relationships
18+
- [ ] Compound documents
19+
- [ ] Related collection pagination
1320
- [ ] Asynchronous processing
1421
- [ ] Optional check for `Content-Type` header in incoming responses
1522

16-
#### Server (The Server API is not stable yet!)
23+
#### Server
1724
- [x] Fetching single resources and resource collections
25+
- [x] Collection pagination
1826
- [x] Fetching relationships and related resources and collections
1927
- [x] Fetching single resources
2028
- [x] Creating resources
2129
- [x] Deleting resources
2230
- [x] Updating resource's attributes
2331
- [x] Updating resource's relationships
24-
- [ ] Updating relationships
25-
- [ ] Inclusion of related resources
32+
- [x] Updating relationships
33+
- [ ] Compound documents
2634
- [ ] Sparse fieldsets
27-
- [ ] Sorting, pagination, filtering
35+
- [ ] Sorting, filtering
36+
- [ ] Related collection pagination
2837
- [ ] Asynchronous processing
2938
- [ ] Optional check for `Content-Type` header in incoming requests
3039
- [ ] Support annotations in resource mappers (?)
3140

32-
#### Document (The Document API is not stable yet!)
41+
#### Document
42+
- [x] Support relationship objects lacking the `data` member
43+
- [ ] Compound documents
3344
- [ ] Support `meta` members
3445
- [ ] Support `jsonapi` members
35-
- [ ] Structure Validation including compound documents
36-
- [ ] Support relationship objects lacking the `data` member
46+
- [ ] Structural Validation including compound documents
3747
- [ ] Naming Validation
3848
- [ ] JSON:API v1.1 features
3949

example/cars_client.dart

Lines changed: 0 additions & 35 deletions
This file was deleted.

example/cars_server.dart

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import 'dart:async';
12
import 'dart:io';
23

3-
import 'package:json_api/src/server/simple_server.dart';
4+
import 'package:json_api/server.dart';
45

56
import 'cars_server/controller.dart';
67
import 'cars_server/dao.dart';
@@ -9,17 +10,20 @@ import 'cars_server/model.dart';
910
void main() async {
1011
final addr = InternetAddress.loopbackIPv4;
1112
final port = 8080;
12-
await createServer().start(addr, port);
13+
await createServer(addr, port);
1314
print('Listening on ${addr.host}:$port');
1415
}
1516

16-
SimpleServer createServer() {
17+
Future<HttpServer> createServer(InternetAddress addr, int port) async {
1718
final models = ModelDAO();
1819
[
1920
Model('1')..name = 'Roadster',
2021
Model('2')..name = 'Model S',
2122
Model('3')..name = 'Model X',
2223
Model('4')..name = 'Model 3',
24+
Model('5')..name = 'X1',
25+
Model('6')..name = 'X3',
26+
Model('7')..name = 'X5',
2327
].forEach(models.insert);
2428

2529
final cities = CityDAO();
@@ -39,10 +43,30 @@ SimpleServer createServer() {
3943
..name = 'BMW'
4044
..headquarters = '1',
4145
Company('3')..name = 'Audi',
46+
Company('4')..name = 'Toyota',
4247
].forEach(companies.insert);
4348

44-
return SimpleServer(CarsController(
45-
{'companies': companies, 'cities': cities, 'models': models}));
49+
final controller = CarsController(
50+
{'companies': companies, 'cities': cities, 'models': models});
51+
52+
final routing = StandardRouting(Uri.parse('http://localhost:$port'));
53+
54+
final server = JsonApiServer(routing);
55+
56+
final httpServer = await HttpServer.bind(addr, port);
57+
58+
httpServer.forEach((request) async {
59+
final route = await routing.getRoute(request.requestedUri);
60+
if (route == null) {
61+
request.response.statusCode = 404;
62+
return request.response.close();
63+
}
64+
route.createRequest(request)
65+
..bind(server)
66+
..call(controller);
67+
});
68+
69+
return httpServer;
4670
}
4771

4872
class Url {

0 commit comments

Comments
 (0)