W3C home > Mailing lists > Public > public-linked-json@w3.org > December 2014

Prototype JSON-LD/Hydra wrapper for BreweryDB API

From: John Walker <john.walker@semaku.com>
Date: Sun, 28 Dec 2014 12:51:26 +0100 (CET)
To: public-hydra@w3.org, public-linked-json@w3.org
Message-ID: <522163058.2716941.1419767486709.open-xchange@oxweb01.eigbox.net>
Hi All,

In my spare time I've been working on a JSON-LD wrapper for BreweryDB and have
reached what I consider to be a demo-able state.

Basically I have a pretty simple (and hacky) PHP script that manipulates the
JSON repsonses from the BrewerDB API into JSON-LD.
It doesn't provide full coveage of the API yet and needs a bit of tidying, I've
put it in a Gist if anyone cares to take a look [2] (bear in mind this is the
first thing I've done in PHP).
Curently it only works fully with the beer endpoints [3] from the original API.

I'm trying to figure out how to handle all the variations in the JSON structure
without using a load of repetition, nested if-then-else and foreach loops, so if
anyone with some PHP knowhow can suggest a better method, I'm all ears.
Also would like to know how I can get rid of index.php out of the following

Some examples:

A beer:

A beer with it's breweries:

A paginated collection of beers of 4% ABV:

These support conneg (to some extent), so you'll probably get plain old JSON if
you open them in your browser.
If you put them into the JSON-LD playground, you should get the JSON-LD e.g.:

I'm also using a bit of Hydra, for example the /beers list endpoint is a
hydra:PagedCollection and I added the links to first, last, previous and next
I am also going to extend the vocabulary to use more Hydra to, for example,
indicate which properties are a hydra:Link  and perhaps detail out some IRI
However as this is just a learning exercise I probably will not cover all
possibilites offered by the original API, but hopefully enough to convince the
BrweryDB guys to implement it themselves.

Comments welcome!

p.s. this is using my API key right now, so might exceed my limits if too many
requests are made (3.5K per day I think).

[1] http://www.brewerydb.com/
[2] https://gist.github.com/jaw111/46209e853f83d041a6dd
[3] http://www.brewerydb.com/developers/docs-endpoint/beer_index


John Walker
Principal Consultant & co-founder
Semaku B.V.
SFJ 4.009, Torenallee 20, 5617 BC Eindhoven
Mobile: +31 6 475 22030
Email: john.walker@semaku.com
Skype: jaw111

KvK: 58031405
BTW: NL852842156B01
IBAN: NL94 INGB 0008 3219 95
Received on Sunday, 28 December 2014 11:51:57 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:18:43 UTC