gabesullice / juissy

Juissy is a minimal experimental JSON API client for Drupal.
7 stars 2 forks source link

Consider being HTTP agent agnostic #2

Open e0ipso opened 5 years ago

e0ipso commented 5 years ago

Problem

I see that this project relies on the Fetch API https://github.com/gabesullice/juissy/blob/2a18c17aab01fa048fce1d6ed72cdc03fadb4b0d/src/index.js#L264.

This API is fantastic and has great adoption among the major browsers. However, that is not the case for node.js.

Isomorphic applications using this library will need to pollute their globals with an undocumented polyfil of the fetch API. Also, projects depending on axios (like nuxt.js, gatsby.js, …) will have to include 2 different HTTP libraries.

Proposed Solution

I propose that this project is only in charge of generating the query string that will be send to Drupal. That'll include sugar syntax for:

For features that require HTTP requests, like the automatic pagination we need an HTTP client library. Instead of choosing one ourselves, we could accept it as a parameter to the JuissyClient. If we do that the problem is that different libs have different APIs (fetch, request, axios, got, node, …). In that case we could try to provide adaptors to the primary library we choose (in this case fetch).

gabesullice commented 5 years ago

I'm not willing to go so far as to make this library only generate the URL which one should request. BUT, I'd certainly like to factor out the query string generator for fancy filters into a subpackage (or separate project even) that you could import independently.

~I'd love to work with you to figure out a way to make the fetch (or axios) or whatever injectable.~

I see you actually proposed that in the end of your comment. +1