rjsonapi

knitr::opts_chunk$set(
  warning = FALSE,
  message = FALSE,
  collapse = TRUE,
  comment = "#>"
)

Build Status cran checks codecov.io cran version

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

Setup a JSONAPI

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")

Connect

(conn <- jsonapi_connect("http://localhost:8088", "v1"))

Get API info

Get version

conn$version

Get base URL

conn$base_url()

Get server status

conn$status()

Get routes (not available in a standard JSONAPI i think)

conn$routes()

Call a route

books route

conn$route("authors")

Get a single document

First authors document

conn$route("authors/1")

Sub-part under that document: books

conn$route("authors/1/books")

A different sub-part under that document: photos

conn$route("authors/1/photos")

Experimental - startup a server from R

In one R session:

jsonapi_server()
#> Starting server to listen on port 8000

Then in another R session:

Connect to the server:

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

Get routes

conn$routes()

Get chapters

conn$route("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



sckott/rjsonapi documentation built on May 20, 2022, 1:12 p.m.