An R client for consuming APIs that follow the JSONAPI spec. This library does not do server side JSONAPI things.

Setup a JSONAPI

  • git clone [email protected]:endpoints/endpoints-example.git (or via hub: hub clone endpoints/endpoints-example)
  • cd endpoints-example
  • npm install
  • PORT=8088 npm start (start with port 8088 instead of 8080, can use a different port) - OR, npm install forever, then PORT=8088 forever start -c "npm start" '.'

Which starts a server. Then point your browser to e.g.:

Install rjsonapi R client

Stabler version

install.packages("rjsonapi")

Dev version

devtools::install_github("ropensci/rjsonapi")
library("rjsonapi")

Get a single document

First authors document

Sub-part under that document: books

conn$route("authors/1/books")
#> $data
#>   id  type attributes.date_published           attributes.title
#> 1  1 books                1954-07-29 The Fellowship of the Ring
#> 2  2 books                1954-11-11             The Two Towers
#> 3  3 books                1955-10-20         Return of the King
#> 4 11 books                1937-09-21                 The Hobbit
#>   attributes.created_at attributes.updated_at
#> 1   2017-08-24 22:44:53   2017-08-24 22:44:53
#> 2   2017-08-24 22:44:53   2017-08-24 22:44:53
#> 3   2017-08-24 22:44:53   2017-08-24 22:44:53
#> 4   2017-08-24 22:44:53   2017-08-24 22:44:53
#>       relationships.chapters.links.self
#> 1  /v1/authors/1/relationships/chapters
#> 2  /v1/authors/2/relationships/chapters
#> 3  /v1/authors/3/relationships/chapters
#> 4 /v1/authors/11/relationships/chapters
#>   relationships.chapters.links.related
#> 1               /v1/authors/1/chapters
#> 2               /v1/authors/2/chapters
#> 3               /v1/authors/3/chapters
#> 4              /v1/authors/11/chapters
#>       relationships.firstChapter.links.self
#> 1  /v1/authors/1/relationships/firstChapter
#> 2  /v1/authors/2/relationships/firstChapter
#> 3  /v1/authors/3/relationships/firstChapter
#> 4 /v1/authors/11/relationships/firstChapter
#>   relationships.firstChapter.links.related
#> 1               /v1/authors/1/firstChapter
#> 2               /v1/authors/2/firstChapter
#> 3               /v1/authors/3/firstChapter
#> 4              /v1/authors/11/firstChapter
#>       relationships.series.links.self relationships.series.links.related
#> 1  /v1/authors/1/relationships/series               /v1/authors/1/series
#> 2  /v1/authors/2/relationships/series               /v1/authors/2/series
#> 3  /v1/authors/3/relationships/series               /v1/authors/3/series
#> 4 /v1/authors/11/relationships/series              /v1/authors/11/series
#>   relationships.series.data.id relationships.series.data.type
#> 1                            1                         series
#> 2                            1                         series
#> 3                            1                         series
#> 4                         <NA>                           <NA>
#>       relationships.author.links.self relationships.author.links.related
#> 1  /v1/authors/1/relationships/author               /v1/authors/1/author
#> 2  /v1/authors/2/relationships/author               /v1/authors/2/author
#> 3  /v1/authors/3/relationships/author               /v1/authors/3/author
#> 4 /v1/authors/11/relationships/author              /v1/authors/11/author
#>   relationships.author.data.id relationships.author.data.type
#> 1                            1                        authors
#> 2                            1                        authors
#> 3                            1                        authors
#> 4                            1                        authors
#>       relationships.stores.links.self relationships.stores.links.related
#> 1  /v1/authors/1/relationships/stores               /v1/authors/1/stores
#> 2  /v1/authors/2/relationships/stores               /v1/authors/2/stores
#> 3  /v1/authors/3/relationships/stores               /v1/authors/3/stores
#> 4 /v1/authors/11/relationships/stores              /v1/authors/11/stores
#>       relationships.photos.links.self relationships.photos.links.related
#> 1  /v1/authors/1/relationships/photos               /v1/authors/1/photos
#> 2  /v1/authors/2/relationships/photos               /v1/authors/2/photos
#> 3  /v1/authors/3/relationships/photos               /v1/authors/3/photos
#> 4 /v1/authors/11/relationships/photos              /v1/authors/11/photos
#>             self
#> 1  /v1/authors/1
#> 2  /v1/authors/2
#> 3  /v1/authors/3
#> 4 /v1/authors/11

A different sub-part under that document: photos

Experimental - startup a server from R

In one R session:

Then in another R session:

Connect to the server:

(conn <- jsonapi_connect("http://localhost:8000"))

Get routes

Get chapters

Note: This server stuff is still in infancy. Working on getting a more complete set of routes and data.

Right now, jsonapi_server() only loads data that comes with this package - in the future it will support your own data.

Meta

rofooter