Type: Package
Title: R Interface to RESTful Web Services
Version: 0.0.16
Description: Models a RESTful service as if it were a nested R list.
License: Artistic-2.0
Imports: XML, RCurl, rjson, S4Vectors (≥ 0.13.15), yaml
Depends: R (≥ 3.4.0), methods
Suggests: getPass, rsolr, RUnit
Collate: CRUDProtocol-class.R CacheInfo-class.R Credentials-class.R HTTP-class.R Media-class.R MediaCache-class.R RestUri-class.R RestContainer-class.R test_restfulr_package.R utils.R
NeedsCompilation: yes
Packaged: 2025-06-27 17:35:34 UTC; michafla
Author: Michael Lawrence [aut, cre]
Maintainer: Michael Lawrence <michafla@gene.com>
Repository: CRAN
Date/Publication: 2025-06-27 18:20:02 UTC

CRUDProtocol

Description

CRUDProtocol is a base class for implementing the communication protocol for performing Create, Read, Update and Delete (CRUD) operations on a resource identified by a RestUri. Only HTTP is implemented by this package, and it should serve as useful example for other implementations.

Author(s)

Michael Lawrence


Credentials

Description

Credentials stores authentication credentials (username and password). Note that it is easy to retrieve the password from this object. There is no encryption or other security.

Accessors

Author(s)

Michael Lawrence


Media

Description

The Media object represents a value identified by a URI. There is a Media subclass for each media type, such as “text/csv” or “application/xml”. Coercion methods (see setAs) define mappings between Media subclasses and R objects. The user does not usually need to access this functionality directly.

Type conversion

Each Media subclass may be converted to/from one or more R types. The mappings are established by setAs.

The following bi-directional mappings are built into the package:

application/xml, text/html XMLAbstractNode
application/json list
text/csv data.frame
text/* character

But call mediaCoercionTable to see what is defined in the current session.

The as function is the canonical interface to converting media to R objects. It (usefully) requires that the user specify the target R type. For convenience, the mediaTarget generic returns the default R type for a given Media object.

To support a new media type, one should define a Media subclass with the same name as the media type (application/xml), a corresponding mediaTarget method, and all relevant coerce methods. See the Media class hierarchy to determine where the new type fits.

Helpers

Author(s)

Michael Lawrence

Examples

txt <- '{"json":{"rocks":true}}'
json <- as(txt, "application/json")
as(json, mediaTarget(json))

MediaCache

Description

MediaCache is just an environment that restricts the types of its elements to Media. Construct an instance by calling MediaCache. The shared default for all REST clients is returned by globalRestClientCache.

Author(s)

Michael Lawrence


RestContainer

Description

The RestContainer object wraps a collection of resources with a list-like interface. Values are stored and retrieved using familiar accessors like [[ and [[<-. Coercion between external media and R objects is based on the Media framework.

Data access

The RestContainer object maps familiar R list accessors to CRUD operations on RestUri.

Constructor

Author(s)

Michael Lawrence

See Also

RestUri, which is a lower-level but perhaps more sensible interface.

Examples

apache <- RestContainer("http://wiki.apache.org")
apache$solr

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.

Constructor

Container support

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

Author(s)

Michael Lawrence

Examples

apache <- RestUri("http://wiki.apache.org")
## Not run: 
    read(apache$solr)

## End(Not run)