Laravel: JSON ORM for remote resources

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

Italo Baeza Cabrera
2 min readSep 25, 2018
“grayscale photo of remote beside eyeglasses” by Steve Johnson on Unsplash

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.

--

--

Italo Baeza Cabrera

Graphic Designer graduate. Full Stack Web Developer. Retired Tech & Gaming Editor. https://italobc.com