RestUri-class {restfulr} | R Documentation |
RestUri
Description
The RestUri
object represents a resource accessible via a
RESTful interface. It extends character
with a protocol, used
for accessing the data, as well as a cache. R objects are converted
to/from external media via the Media
framework.
CRUD interface
There are four canonical, abstract types of REST operations: create,
read, update, delete (CRUD). The CRUD model was borrowed from
traditional databases. The restfulr package maps those four operations
to R functions of the same name. The functions are generic, and there
are methods for RestUri
and character
(taken to be a
URI), described below.
-
create(x, value, ..., returnResponse=FALSE)
: Creates a resource atx
by convertingvalue
to a supported media type. The ... become query parameters onx
. IfreturnResponse
isTRUE
, convert and return any response sent from the endpoint. By default,x
is returned, to support chaining. This corresponds to an HTTPPOST
. -
read(x, ...)
: Reads the resource atx
, coerces it to an R object, and returns the object. The ... become query parameters onx
. This corresponds to an HTTPGET
. -
update(object, value, ...)
: Updates the resource atx
by convertingvalue
to a supported media type. The ... become query parameters onx
. This corresponds to an HTTPPUT
. -
delete(x, ...)
: Deletes the resource atx
. This corresponds to an HTTPDELETE
.
Constructor
-
RestUri(base.uri, protocol = CRUDProtocol(base.uri, ...), cache = globalRestClientCache(), ...)
: Constructs aRestUri
object, pointing tobase.uri
, a string representation of the URI. Theprotocol
(aCRUDProtocol
instance) is automatically determined from the scheme of the URI. By default, all instances share the same globalcache
, aMediaCache
instance. x$name
: Extends the path ofx
by appendingname
. This is a convenient way to narrow a URI and is intuitive if one thinks of a tree of resources as a nested list.x[[i]]
: Extends the path ofx
by appendingi
.x[...]
: Named arguments in...
become query parameters onx
.
Container support
-
container(x)
: Gets aRestContainer
object for treatingx
as a list-like container.
Authentication
RestUri currently supports basic HTTP authentication. Call
authenticate(x)
to add credentials to the RestUri
x
. Retrieve the Credentials object with the credentials
accessor.
Once a set of credentials has been entered, it is recorded for the URI in ‘$(HOME)/.local/config/restfulr/credentials.yaml’. The path prefix can be changed via the XDG_CONFIG_DIR environment variable, according to the XDG standard. The credential cache is checked during authentication, so that a user does not need to reenter credentials for the same URI.
If the getPass package is installed, we use it for password entry. Otherwise, we rely on an implementation that shows the password as it is entered, unless the user is in a terminal, where we can hide input.
Utilities
embedCredentials(x)
: Embeds the internal credential information into the URL itself, for interfacing with other tools, likeutils::download.file
.
Author(s)
Michael Lawrence
Examples
apache <- RestUri("http://wiki.apache.org")
read(apache$solr)