plumber (version 1.0.0)

parser_form: Plumber Parsers

Description

Parsers are used in Plumber to transform the raw body content received by a request to the API. Extra parameters may be provided to parser functions when adding the parser to plumber. This will allow for non-default behavior.

Usage

parser_form()

parser_json(...)

parser_text(parse_fn = identity)

parser_yaml(...)

parser_csv(...)

parser_tsv(...)

parser_read_file(read_fn = readLines)

parser_rds(...)

parser_feather(...)

parser_octet()

parser_multi()

parser_none()

Arguments

...

parameters supplied to the appropriate internal function

parse_fn

function to further decode a text string into an object

read_fn

function used to read a the content of a file. Ex: readRDS()

Functions

  • parser_form: Form query string parser

  • parser_json: JSON parser. See jsonlite::parse_json() for more details. (Defaults to using simplifyVectors = TRUE)

  • parser_text: Helper parser to parse plain text

  • parser_yaml: YAML parser. See yaml::yaml.load() for more details.

  • parser_csv: CSV parser. See readr::read_csv() for more details.

  • parser_tsv: TSV parser. See readr::read_tsv() for more details.

  • parser_read_file: Helper parser that writes the binary body to a file and reads it back again using read_fn. This parser should be used when reading from a file is required.

  • parser_rds: RDS parser. See readRDS() for more details.

  • parser_feather: feather parser. See feather::read_feather() for more details.

  • parser_octet: Octet stream parser. Returns the raw content.

  • parser_multi: Multi part parser. This parser will then parse each individual body with its respective parser. When this parser is used, req$body will contain the updated output from webutils::parse_multipart() by adding the parsed output to each part. Each part may contain detailed information, such as name (required), content_type, content_disposition, filename, (raw, original) value, and parsed (parsed value). When performing Plumber route argument matching, each multipart part will match its name to the parsed content.

  • parser_none: No parser. Will not process the postBody.

Details

Parsers are optional. When unspecified, only the parser_json(), parser_octet(), parser_form() and parser_text() are available. You can use @parser parser tag to activate parsers per endpoint. Multiple parsers can be activated for the same endpoint using multiple @parser parser tags.

User should be aware that rds parsing should only be done from a trusted source. Do not accept rds files blindly.

See registered_parsers() for a list of registered parsers.

Examples

Run this code
# NOT RUN {
# Overwrite `text/json` parsing behavior to not allow JSON vectors to be simplified
#* @parser json simplifyVector = FALSE
# Activate `rds` parser in a multipart request
#* @parser multi
#* @parser rds
pr <- Plumber$new()
pr$handle("GET", "/upload", function(rds) {rds}, parsers = c("multi", "rds"))
# }

Run the code above in your browser using DataLab