matchTarget method
Matches a uri
to a Target object.
Implementation
Target? matchTarget(Uri uri) => !uri.path.startsWith(base.path) ||
(base.scheme.isNotEmpty && uri.scheme != base.scheme) ||
(base.host.isNotEmpty && uri.host != base.host) ||
(base.port != 0 && uri.port != base.port)
? null
: switch (uri.pathSegments
.sublist(base.pathSegments.where((it) => it.isNotEmpty).length)) {
[var type] => Target(type),
[var type, var id] => ResourceTarget(type, id),
[var type, var id, var rel] => RelatedTarget(type, id, rel),
[var type, var id, 'relationships', var rel] =>
RelationshipTarget(type, id, rel),
_ => null
};