Create a porcelain_endpoint
object that collects
together an HTTP method (e.g., GET
), a path (e.g.,
/path
) and a target R function. Unlike plumber
endpoints, porcelain endpoints are meant to be used in testing.
method
HTTP method
path
HTTP path
target
R function used for the endpoint
validate
Logical, indicating if response validation is used
inputs
Input control
state
Possibly mutable state
returning
An porcelain_returning
object
controlling the return type (content type, status code,
serialisation and validation information).
new()
Create an endpoint
porcelain_endpoint$new(method, path, target, ..., returning, validate = NULL)
method
The HTTP method to support
path
The server path for the endpoint
target
An R function to run as the endpoint
...
Additional parameters, currently representing
inputs. You can use the functions
porcelain_input_query
,
porcelain_input_body_binary
and
porcelain_input_body_json
to define inputs and pass
them into this method. The names used must match those in
target
.
returning
Information about what the endpoint returns,
as created by porcelain_returning
validate
Logical, indicating if any validation
(implemented by the validate_response
argument) should
be enabled. This should be set to FALSE
in production
environments. By default (if validate
is NULL
),
we look at the value of the environment PORCELAIN_VALIDATE
-
if true
(case insensitive) then we will validate.
This is intended to support easy use of validation on
continuous integration systems.
validate_response
Optional function that throws an error of the processed body is "invalid".
run()
Run the endpoint. This will produce a
standardised response object that contains status_code
,
content_type
, body
(the serialised output as run
through the process
method and returned by plumber) and
data
(the result of running the target function)
request()
Test the endpoint. This creates a full plumber
object and serves one request to the endpoint. Argument are as
passed through to porcelain
's $request()
method, except that method
and path
are
automatically taken from the endpoint itself.
plumber()
Helper method for use with plumber - not designed for end-user use. This is what gets called by plumber when the endpoint receives a request.