Learn R Programming

rjsonapi (version 0.1.0)

jsonapi_connect: Connection

Description

Connection

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 HttpClient. You can set these for all requests, or on each request - see examples.

Details

Methods

Examples

Run this code
## 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)

Run the code above in your browser using DataLab