handle method

Future<Response> handle(
  1. Request request
)

Implementation

Future<Response> handle(Request request) async {
  _validate(request);
  final target = _matchTarget(request.uri);
  return await switch (target) {
    RelationshipTarget() => switch (request.method) {
        'get' => _controller.fetchRelationship(request, target),
        'post' => _controller.addMany(request, target),
        'patch' => _controller.replaceRelationship(request, target),
        'delete' => _controller.deleteMany(request, target),
        _ => throw MethodNotAllowed(request.method)
      },
    RelatedTarget() => switch (request.method) {
        'get' => _controller.fetchRelated(request, target),
        _ => throw MethodNotAllowed(request.method)
      },
    ResourceTarget() => switch (request.method) {
        'get' => _controller.fetchResource(request, target),
        'patch' => _controller.updateResource(request, target),
        'delete' => _controller.deleteResource(request, target),
        _ => throw MethodNotAllowed(request.method)
      },
    Target() => switch (request.method) {
        'get' => _controller.fetchCollection(request, target),
        'post' => _controller.createResource(request, target),
        _ => throw MethodNotAllowed(request.method)
      },
    _ => throw UnmatchedTarget(request.uri)
  };
}