Laravel: JSON ORM for remote resources

Consuming JSON resources from a REST API doesn’t have to be a pain.

Image for post
Image for post
“grayscale photo of remote beside eyeglasses” by on

In my app I needed to consume remote resources constantly. Of course, Guzzle HTTP Client and a Repository was the first thing it came to my mind.

It worked until the cluttered code was unbearable and I couldn’t debug what I was doing, let alone repeating code. Then in the course of 7 days during my local holidays I made a JSON ORM and Query Builder package. Probably my first serious package.

What is JSON ORM?

Think about a Remote Database, that instead of Eloquent Models it has Documents, and work almost the same. Installing the package will allow you to make something like this:

$color = RemoteColor::whereImplicit('red')->first()$color->name = 'purple';$color->save();

Of course, every JSON API and REST API is different, so the package comes with the following pieces that you can change with your own if you don’t like it:

  • Grammar — Transform the Query to something your API understands.
  • Dispatch the Request to the API, with your own HTTP Client.
  • Sign the content in some way, if the API needs it.
  • Process the Response you get.

So head to composer at test it.

Graphic Designer graduate. Full Stack Web Developer. Retired Tech & Gaming Editor.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store