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

Command icon 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

brianperry created an issue. See original summary.

brianperry’s picture

Status: Active » Needs work

This is mostly addressed by our initial project scaffolding, but I think likely needs more complete tests and possibly improved documentation.

brianperry’s picture

Assigned: Unassigned » brianperry
brianperry’s picture

Assigned: brianperry » Unassigned
brianperry’s picture

Issue tags: +Needs tests

Here'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.

pratik_kamble’s picture

Assigned: Unassigned » pratik_kamble
Status: Needs work » Active

pratik_kamble’s picture

Assigned: pratik_kamble » Unassigned
Status: Active » Needs review

brianperry’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests

Made one adjustment - changed our mock endpoint to use a response that matches the jsonapi spec. Aside from that, this looks great - thanks @pratik_kamble

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.