Add SimpleJSONAPIClient to Ruby implementations #1257
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Exactly what it says.
For context: The reason this project exists is because none of the listed Ruby implementations allow you to switch request context (e.g. use a different Authorization header) across multiple requests; they all require setting global state. They also tend to assume APIs allow all the usual JSONAPI routes, and many don't (working with e.g. Rails' shallow routes often doesn't seem possible). In my use case, I needed to allow using different API keys on a per-request basis, and some of the routes of this API are, though compliant, somewhat complicated.
Once I had to start from scratch, I ended up building a framework for building Ruby clients that tries to balance between allowing more low-level per-request tweaks, leveraging the power of JSON API
filter
andincludes
, using a lot of laziness, but still making most of the complexity optional through semantically parsing the responses and fetching related records as-needed.I appreciate the beauty of
post.authors.map(&:comments)
, but I was less convinced of the need to use relational algebra to enableincludes
throughPost.includes(author: :comments).find(1)
whenPost.fetch(url_opts: { id: 1 }, includes: ['author.comments'])
works just fine. I get why other people like it, I just thought a simpler solution might be all that's necessary.That said, the syntax isn't the main goal here; it's more about customization of routes and request details, which weren't provided by any solution I could find.