Problem/Motivation
We need to create an initial (and bare bones) ApiClient class that we can extend and build upon. This might end up being taken care of or started by way of https://www.drupal.org/project/api_client/issues/3365959 but this issue can at least be used to validate the requirements for that implementation.
Proposed resolution
* The JsonApiClient class will extend the ApiClient class.
* If an apiPrefix is not provided, 'jsonapi' will be used by default.
* The JsonApiClient class will implement a getCollection method that:
** takes an argument of 'type' (string)
** Makes a request to `${this.baseUrl}/${this.apiPrefix}` to determine the appropriate endpoint for that resource type.
** Fetches data from that endpont, returning data as json.
Remaining tasks
* Implement the ApiClient class
* Define necessary types
* Document the current ApiClient class inline.
* Add test coverage.
API changes
The JsonApiClient class will be created.
Issue fork api_client-3374188
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
brianperryThis is mostly addressed by our initial project scaffolding, but I think likely needs more complete tests and possibly improved documentation.
Comment #3
brianperryComment #4
brianperryComment #5
brianperryHere's what I think is missing from the perspective of tests and docs:
Tests:
* If an API prefix is provided, it will be used. Otherwise, the default of 'jsonapi' will be used.
* In the get method, the url is assembled correctly based on input and the expected fetch request is made.
Docs:
* A tsdoc comment is added for the constructor.
* A tsdoc comment is added for the get method.
The ApiClient class has some relevant tests and docs, so I'd suggest consulting that for reference.
Comment #6
pratik_kambleComment #8
pratik_kambleComment #10
brianperryMade one adjustment - changed our mock endpoint to use a response that matches the jsonapi spec. Aside from that, this looks great - thanks @pratik_kamble