Decoupled Router Support

Created on 1 November 2023, about 1 year ago
Updated 21 February 2024, 9 months ago

Problem/Motivation

Support for decoupled router is a common request, and many existing clients support it.

It isn't part of core though, so we'll need to determine the best way to support something like that. Would it be a separate package? Or does it need to be part of the JsonApiClient to be useful?

Steps to reproduce

This Astro template provides an example of what it looks like sourcing content based on route with the current state of the client. Not the end of the world (the grossest part imho is getting at the relationships without using deserialized data) but with router support and using a deserializer this gets down to a single line of code.

Proposed resolution

Some initial thoughts on how we could approach this:

* Create a new decoupled-router-client package that extends the ApiClient base class.
* Add a DecoupledRouterClient instance as a property on the JsonApiClient class.
* Implement a getResourceByPath method on the JsonApiClient class.

This approach doesn't completely solve the issue that the JsonApiClient will now provide functionality related to something that isn't in core, but I think the standalone package is the best we can do. And I also think offering a standalone decoupled router package has value in general. I also like that this will continue to exercise the decisions we made with the base class.

Remaining tasks

* Implement decoupled-router-client package.
* Implement getResourceByPath method on JsonApiClient
* Documentation
* Tests
* Examples

API changes

* Introduces decoupled-router-client package.
* Introduces getResourceByPath method - getResourceByPath(type: EntityTypeWithBundle, path: string, options?: GetOptions)

Data model changes

* We'll have some router specific types as a result of this, which feels like a good thing.

✨ Feature request
Status

Fixed

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States brianperry

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @brianperry
  • πŸ‡ΊπŸ‡ΈUnited States brianperry

    +1 for this feature on the POC feedback issue. https://www.drupal.org/project/api_client/issues/3398219 β†’

  • Assigned to brianperry
  • πŸ‡ΊπŸ‡ΈUnited States brianperry

    Updated the issue with some thoughts on how we could accomplish this. Planning on starting a branch to tinker on this.

  • Pipeline finished with Success
    10 months ago
    Total: 147s
    #78932
  • I like the approach of breaking this off into a new package. Should it extend the JsonApiClient so that a user wouldn't need to create multiple clients for all of the functionality?

  • πŸ‡ΊπŸ‡ΈUnited States brianperry

    > Should it extend the JsonApiClient so that a user wouldn't need to create multiple clients for all of the functionality?

    I'll take a closer look at this as I continue to work on it, but I believe the Decoupled Router endpoint technically doesn't follow the JSON:API spec. That was the main reason I assumed we'd extend the base class. I also think many of the methods on the JsonApiClient class wouldn't apply to that endpoint.

  • Pipeline finished with Success
    10 months ago
    Total: 147s
    #80298
  • Pipeline finished with Success
    10 months ago
    Total: 151s
    #80479
  • Pipeline finished with Success
    10 months ago
    #81967
  • Pipeline finished with Success
    10 months ago
    #82425
  • Pipeline finished with Success
    10 months ago
    #82797
  • Pipeline finished with Success
    10 months ago
    Total: 179s
    #83521
  • Pipeline finished with Success
    10 months ago
    Total: 179s
    #84313
  • Pipeline finished with Success
    10 months ago
    Total: 148s
    #84370
  • Pipeline finished with Success
    10 months ago
    Total: 183s
    #84476
  • Pipeline finished with Success
    10 months ago
    Total: 183s
    #85010
  • Pipeline finished with Success
    10 months ago
    Total: 335s
    #85667
  • Pipeline finished with Success
    10 months ago
    Total: 148s
    #85736
  • Pipeline finished with Success
    10 months ago
    Total: 149s
    #85738
  • Merge request !39Decoupled Router Support β†’ (Merged) created by brianperry
  • Issue was unassigned.
  • Status changed to Needs review 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States brianperry
  • Pipeline finished with Success
    10 months ago
    Total: 343s
    #85743
  • Pipeline finished with Success
    10 months ago
    Total: 246s
    #85745
  • Pipeline finished with Success
    10 months ago
    Total: 272s
    #87474
  • Status changed to RTBC 10 months ago
  • Status changed to Fixed 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States brianperry
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024