jsonapi_connect: Connection

View source: R/connect.R

jsonapi_connectR Documentation

Connection

Description

Connection

Usage

jsonapi_connect(url, version, content_type, headers, ...)

Arguments

url

(character) Base url, without the version information, e.g., http://localhost:8088

version

(character) API version. Default: v1

content_type

(character) the content type to set in all request headers. Default: 'application/vnd.api+json'

headers

(list) A list of headers to be applied to each requset.

...

Curl options passed on to crul::verb-GET. You can set these for all requests, or on each request - see examples.

Details

Methods

  • status(...): Check server status with a HEAD request

    • ...: curl options passed on to crul::verb-GET

  • routes(...): Get routes the server supports

    • ...: curl options passed on to crul::verb-GET

  • route(endpt, query, include, error_handler, ...): Fetch a route, optional query parameters

    • endpt: The endpoint to request data from. required.

    • query: a set of query parameters. combined with include parameter

    • include: A comma-separated list of relationship paths. combined with query parameter

    • error_handler: A function for error handling

    • ...: curl options passed on to crul::verb-GET

Examples

## Not run: 
library("crul")
(conn <- jsonapi_connect("http://localhost:8088"))
conn$url
conn$version
conn$content_type
conn$status()
conn$routes()
conn$routes(verbose = TRUE)

# get data from speicific routes
conn$route("authors")
conn$route("chapters")
conn$route("authors/1")
conn$route("authors/1/books")
conn$route("chapters/5")
conn$route("chapters/5/book")
conn$route("chapters/5/relationships/book")

## include
conn$route("authors/1", include = "books")
conn$route("authors/1", include = "photos")
conn$route("authors/1", include = "photos.title")

## set curl options on jsonapi_connect() call
xx <- jsonapi_connect("http://localhost:8088", verbose = TRUE)
xx$opts
xx$status()

## set headers on initializing the client
(conn <- jsonapi_connect("http://localhost:8088", headers = list(foo = "bar")))

## errors
### route doesn't exist
# conn$route("foobar")

### document doesn't exist
# conn$route("authors/56")

## End(Not run)

ropensci/rjsonapi documentation built on May 18, 2022, 6:41 p.m.