Method new()
Creates Application object.
Usage
Application$new(
middleware = list(EncodeDecodeMiddleware$new()),
content_type = "text/plain",
...
)
Arguments
middleware
List of Middleware objects.
content_type
Default response body content (media) type. "text/plain"
by default.
...
Not used at the moment.
Method add_route()
Adds endpoint and register user-supplied R function as a handler.
Usage
Application$add_route(
path,
method,
FUN,
match = c("exact", "partial", "regex"),
...
)
Arguments
path
Endpoint path.
method
HTTP method. Allowed methods at the moment:
GET
, HEAD
, POST
, PUT
, DELETE
, OPTIONS
, PATCH
.
FUN
User function to handle requests. FUN
must take two arguments:
first is request
(Request) and second is response
(Response).
The goal of the user function is to modify response
or throw
exception (call raise()
or stop()
).
Both response
and request
objects modified in-place and internally
passed further to RestRserve execution pipeline.
match
Defines how route will be processed. Allowed values:
exact
- match route as is. Returns 404 if route is not matched.
partial
- match route as prefix. Returns 404 if prefix are not matched.
regex
- match route as template. Returns 404 if template pattern not matched.
...
Not used.
Method add_get()
Shorthand to Application$add_route()
with GET
method.
Usage
Application$add_get(
path,
FUN,
match = c("exact", "partial", "regex"),
...,
add_head = TRUE
)
Arguments
path
Endpoint path.
FUN
User function to handle requests. FUN
must take two arguments:
first is request
(Request) and second is response
(Response).
The goal of the user function is to modify response
or throw
exception (call raise()
or stop()
).
Both response
and request
objects modified in-place and internally
passed further to RestRserve execution pipeline.
match
Defines how route will be processed. Allowed values:
exact
- match route as is. Returns 404 if route is not matched.
partial
- match route as prefix. Returns 404 if prefix are not matched.
regex
- match route as template. Returns 404 if template pattern not matched.
...
Not used.
add_head
Adds HEAD method.
Method add_post()
Shorthand to Application$add_route()
with POST
method.
Usage
Application$add_post(path, FUN, match = c("exact", "partial", "regex"), ...)
Arguments
path
Endpoint path.
FUN
User function to handle requests. FUN
must take two arguments:
first is request
(Request) and second is response
(Response).
The goal of the user function is to modify response
or throw
exception (call raise()
or stop()
).
Both response
and request
objects modified in-place and internally
passed further to RestRserve execution pipeline.
match
Defines how route will be processed. Allowed values:
exact
- match route as is. Returns 404 if route is not matched.
partial
- match route as prefix. Returns 404 if prefix are not matched.
regex
- match route as template. Returns 404 if template pattern not matched.
...
Not used.
Method add_static()
Adds GET
method to serve file or directory at file_path
.
Usage
Application$add_static(path, file_path, content_type = NULL, ...)
Arguments
path
Endpoint path.
file_path
Path file or directory.
content_type
MIME-type for the content.
If content_type = NULL
then MIME code content_type
will be inferred
automatically (from file extension).
If it will be impossible to guess about file type then content_type
will
be set to application/octet-stream
.
...
Not used.
Method add_openapi()
Adds endpoint to serve OpenAPI description of
available methods.
Usage
Application$add_openapi(path = "/openapi.yaml", file_path = "openapi.yaml")
Arguments
path
path Endpoint path.
file_path
Path to the OpenAPI specification file.
Method add_swagger_ui()
Adds endpoint to show Swagger UI.
Usage
Application$add_swagger_ui(
path = "/swagger",
path_openapi = "/openapi.yaml",
use_cdn = TRUE,
path_swagger_assets = "/__swagger__/",
file_path = "swagger-ui.html"
)
Arguments
path
path Endpoint path.
path_openapi
Path to the OpenAPI specification file.
use_cdn
Use CDN to load Swagger UI libraries.
path_swagger_assets
Swagger UI asstes endpoint.
file_path
Path to Swagger UI HTML file.
Method append_middleware()
Appends middleware to handlers pipeline.
Usage
Application$append_middleware(mw)
Arguments
mw
Middleware object.
Method process_request()
Process incoming request and generate Response object.
Usage
Application$process_request(request = NULL)
Arguments
request
Request object.
Useful for tests your handlers before deploy application.
Prints application details.
Usage
Application$print()
Method clone()
The objects of this class are cloneable with this method.
Usage
Application$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.