Title: | Easy Middle Ware Library for 'shiny' |
---|---|
Description: | The best way to implement middle ware for 'shiny' Applications. 'tower' is designed to make implementing behavior on top of 'shiny' easy with a layering model for incoming HTTP requests and server sessions. 'tower' is a very minimal package with little overhead, it is mainly meant for other package developers to implement new behavior. |
Authors: | ixpantia, SRL [cph], Andres Quintero [aut, cre] |
Maintainer: | Andres Quintero <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2024-11-22 05:53:18 UTC |
Source: | https://github.com/ixpantia/tower |
Adds a body to a response, if no content type is set, it will be detected
add_body(res, body)
add_body(res, body)
res |
A response builder object |
body |
The body to add |
The response builder object
Adds a body to a response as JSON
add_body_json(res, body)
add_body_json(res, body)
res |
A response builder object |
body |
The body to add |
The response builder object
Adds a cookie to a response
add_cookie(res, name, value)
add_cookie(res, name, value)
res |
A response builder object |
name |
The name of the cookie |
value |
The value of the cookie |
The response builder object
Adds a DELETE route to a tower
add_delete_route(tower, path, handler)
add_delete_route(tower, path, handler)
tower |
A tower object |
path |
A string containing the path to match |
handler |
A function to call when the route is matched |
The tower with the added DELETE route
Adds a GET route to a tower
add_get_route(tower, path, handler)
add_get_route(tower, path, handler)
tower |
A tower object |
path |
A string containing the path to match |
handler |
A function to call when the route is matched |
The tower with the added GET route
Add an HTTP layer to a tower. This layer will be called before the 'shiny' app's httpHandler.
add_http_layer(tower, layer)
add_http_layer(tower, layer)
tower |
A tower |
layer |
A function that takes a request and returns either
a response. A layer can short circuit by returning a response
directly or call the next layer will |
The tower with the added layer
Adds a PATCH route to a tower
add_patch_route(tower, path, handler)
add_patch_route(tower, path, handler)
tower |
A tower object |
path |
A string containing the path to match |
handler |
A function to call when the route is matched |
The tower with the added PATCH route
Adds a POST route to a tower
add_post_route(tower, path, handler)
add_post_route(tower, path, handler)
tower |
A tower object |
path |
A string containing the path to match |
handler |
A function to call when the route is matched |
The tower with the added POST route
Adds a PUT route to a tower
add_put_route(tower, path, handler)
add_put_route(tower, path, handler)
tower |
A tower object |
path |
A string containing the path to match |
handler |
A function to call when the route is matched |
The tower with the added PUT route
Adds an HTTP layer to a tower
add_route(tower, method = "GET", path, handler)
add_route(tower, method = "GET", path, handler)
tower |
A tower object |
method |
A string containing the HTTP method to match |
path |
A string containing the path to match |
handler |
A function to call when the layer is matched |
The tower with the added route
Add a server layer to a tower. This layer will run before the 'shiny' app's server function. This is useful for adding custom logic to the server function without modifying the original server function.
add_server_layer(tower, layer)
add_server_layer(tower, layer)
tower |
A tower |
layer |
A function that takes input, output, and session and has no return value. This function will be called before the original server function. If you want to short-circuit the server use an exception. |
The tower with the added layer
Splits a shiny.appobj into its parts, the ui and server
app_into_parts(app)
app_into_parts(app)
app |
A shiny.appobj |
A list with the ui and server handlers
Builds an HttpOnly cookie from a key and value
build_http_cookie(key, value)
build_http_cookie(key, value)
key |
A string containing the cookie key |
value |
A string containing the cookie value |
A string containing the formated cookie
Builds a response
build_response(res)
build_response(res)
res |
A response builder object |
A 'shiny' response object
Build a 'shiny' app from a tower. This will create a new 'shiny' app with the specified layers added.
build_tower(tower)
build_tower(tower)
tower |
A tower |
A 'shiny' app object that can be started
Create a new tower to build upon.
create_tower(app)
create_tower(app)
app |
A 'shiny' app object |
A new tower object to add more layers to
Print a tower
## S3 method for class 'tower' print(x, ...)
## S3 method for class 'tower' print(x, ...)
x |
A tower |
... |
Ignored arguments (for compatibility with print) |
No return value, called for side effects
Extracts form data from a request
req_body_form(req)
req_body_form(req)
req |
A request object |
A list containing the form data in the body
Extracts the request body from a JSON request
req_body_json(req, ...)
req_body_json(req, ...)
req |
A request object |
... |
Additional arguments to pass to |
The R object representation of the body's JSON content
Extracts cookies from a request
req_cookies(req)
req_cookies(req)
req |
A request object |
A list containing the cookies
Extracts query parameters from a request
req_query(req)
req_query(req)
req |
A request object |
A list containing the query parameters
Creates a response builder
response_builder()
response_builder()
A response builder object
Sets the content type of a response
set_content_type(res, content_type)
set_content_type(res, content_type)
res |
A response builder object |
content_type |
The content type to set |
The response builder object
Sets or adds a header to a response
set_header(res, name, value)
set_header(res, name, value)
res |
A response builder object |
name |
The name of the header |
value |
The value of the header |
The response builder object
Sets the status of a response
set_status(res, status)
set_status(res, status)
res |
A response builder object |
status |
The status to set |
The response builder object