A PHP library for jsonstorage.net

December 9, 2021 0 By addshore

I first heard about jsonstorage.net when searching around for a quick place to persist some data while writing a Twitter bot.

jsonstorage.net provides a simple JSON storage, with a free tier that can be very useful for small personal projects. The REST API is super simple, GET POST PUT DELETE etc. You can have either public or private JSON objects.

During my first use of this service, I remember writing some random code in PHP to interact with the service and deal with authentication. I remember thinking it would be nice if there were a small library that I could grab off the shelf for this, and it would have saved me some minutes… Today is the day I write that simple library!


You can find the library on packagist and code on Github. It supports all apparent functionality of the API.

For public JSON objects, you can use the full lifecycle, CREATE, GET, PUT, DELETE.

<?php use Addshore\JsonStorageNet\JsonStorageNetClient; require_once __DIR__ . '/vendor/autoload.php'; $store = new JsonStorageNetClient(); // Create $id = $store->create(['foo' => 'bar']); var_dump($id); // GET var_dump($store->get($id)); // PUT $store->put($id, ['foo' => 'baz']); var_dump($store->get($id)); // DELETE $store->delete($id);
Code language: PHP (php)

For private JSON objects, you must create these in an online app ahead of time, and then you can PUT and GET them by ID.

<?php use Addshore\JsonStorageNet\JsonStorageNetClient; require_once __DIR__ . '/vendor/autoload.php'; $store = new JsonStorageNetClient("486f7f97-036e-4332-a89a-gg6d19ty9dbx"); $id = "e4cbb4df-ee30-4e31-97a4-7e99180cghaa/b9cb258e-9d22-8959-a3e3-91a28edce82f"; // GET var_dump($store->get($id)); // PUT $store->put($id, ['foo' => 'baz']); var_dump($store->get($id));
Code language: PHP (php)