serializer_headers {plumber} | R Documentation |
Plumber Serializers
Description
Serializers are used in Plumber to transform the R object produced by a filter/endpoint into an HTTP response that can be returned to the client. See here for more details on Plumber serializers and how to customize their behavior.
Usage
serializer_headers(headers = list(), serialize_fn = identity)
serializer_content_type(type, serialize_fn = identity)
serializer_octet(..., type = "application/octet-stream")
serializer_csv(..., type = "text/csv; charset=UTF-8")
serializer_tsv(..., type = "text/tab-separated-values; charset=UTF-8")
serializer_html(type = "text/html; charset=UTF-8")
serializer_json(..., type = "application/json")
serializer_unboxed_json(auto_unbox = TRUE, ..., type = "application/json")
serializer_geojson(..., type = "application/geo+json")
serializer_rds(version = "2", ascii = FALSE, ..., type = "application/rds")
serializer_feather(type = "application/vnd.apache.arrow.file")
serializer_parquet(type = "application/vnd.apache.parquet")
serializer_yaml(..., type = "text/x-yaml; charset=UTF-8")
serializer_text(
...,
serialize_fn = as.character,
type = "text/plain; charset=UTF-8"
)
serializer_format(..., type = "text/plain; charset=UTF-8")
serializer_print(..., type = "text/plain; charset=UTF-8")
serializer_cat(..., type = "text/plain; charset=UTF-8")
serializer_write_file(type, write_fn, fileext = NULL)
serializer_htmlwidget(..., type = "text/html; charset=UTF-8")
serializer_device(type, dev_on, dev_off = grDevices::dev.off)
serializer_jpeg(..., type = "image/jpeg")
serializer_png(..., type = "image/png")
serializer_svg(..., type = "image/svg+xml")
serializer_bmp(..., type = "image/bmp")
serializer_tiff(..., type = "image/tiff")
serializer_pdf(..., type = "application/pdf")
Arguments
headers |
|
serialize_fn |
Function to serialize the data. The result object will be converted to a character string. Ex: |
type |
The value to provide for the |
... |
extra arguments supplied to respective internal serialization function. |
auto_unbox |
automatically |
version |
the workspace format version to use. |
ascii |
a logical. If |
write_fn |
Function that should write serialized content to the temp file provided. |
fileext |
A non-empty character vector giving the file extension. This value will try to be inferred from the content type provided. |
dev_on |
Function to turn on a graphics device.
The graphics device |
dev_off |
Function to turn off the graphics device. Defaults to |
Functions
-
serializer_headers()
: Add a static list of headers to each return value. Will addContent-Disposition
header if a value is the result ofas_attachment()
. -
serializer_content_type()
: Adds aContent-Type
header to the response object -
serializer_octet()
: Octet serializer. If content is received that does not have a"raw"
type, then an error will be thrown. -
serializer_csv()
: CSV serializer. See also:readr::format_csv()
-
serializer_tsv()
: TSV serializer. See also:readr::format_tsv()
-
serializer_html()
: HTML serializer -
serializer_json()
: JSON serializer. See also:jsonlite::toJSON()
-
serializer_unboxed_json()
: JSON serializer withauto_unbox
defaulting toTRUE
. See also:jsonlite::toJSON()
-
serializer_geojson()
: GeoJSON serializer. See alsogeojsonsf::sf_geojson()
and [geojsonsf::sfc_geojson()
]. -
serializer_rds()
: RDS serializer. See also:base::serialize()
-
serializer_feather()
: feather serializer. See also:arrow::write_feather()
-
serializer_parquet()
: parquet serializer. See also:arrow::write_parquet()
-
serializer_yaml()
: YAML serializer. See also:yaml::as.yaml()
-
serializer_text()
: Text serializer. See also:as.character()
-
serializer_format()
: Text serializer. See also:format()
-
serializer_print()
: Text serializer. Captures the output ofprint()
-
serializer_cat()
: Text serializer. Captures the output ofcat()
-
serializer_write_file()
: Write output to a temp file whose contents are read back as a serialized response.serializer_write_file()
creates (and cleans up) a temp file, calls the serializer (which should write to the temp file), and then reads the contents back as the serialized value. If the contenttype
starts with"text"
, the return result will be read into a character string, otherwise the result will be returned as a raw vector. -
serializer_htmlwidget()
: htmlwidget serializer. See also:htmlwidgets::saveWidget()
-
serializer_device()
: Helper method to create graphics device serializers, such asserializer_png()
. See also:endpoint_serializer()
-
serializer_jpeg()
: JPEG image serializer. See also:grDevices::jpeg()
-
serializer_png()
: PNG image serializer. See also:grDevices::png()
-
serializer_svg()
: SVG image serializer. See also:grDevices::svg()
-
serializer_bmp()
: BMP image serializer. See also:grDevices::bmp()
-
serializer_tiff()
: TIFF image serializer. See also:grDevices::tiff()
-
serializer_pdf()
: PDF image serializer. See also:grDevices::pdf()