A parser is responsible for decoding the raw body content of a request into a list of arguments that can be mapped to endpoint function arguments. For instance, parser_json() parse content-type application/json.

register_parser(alias, parser, fixed = NULL, regex = NULL, verbose = TRUE)

registered_parsers()

## Arguments

alias An alias to map parser from the @parser plumber tag to the global parsers list. The parser function to be added. This build the parser function. See Details for more information. A character vector of fixed string to be matched against a request content-type to use parser. A character vector of regex string to be matched against a request content-type to use parser. Logical value which determines if a warning should be displayed when alias in map are overwritten.

## Details

When parser is evaluated, it should return a parser function. Parser matching is done first by content-type header matching on fixed then by using a regular expressions on regex. Note that plumber strip the header from ; charset* to perform matching.

There is a special case when no content-type header is provided that will use a parser_json() when it detects a json string.

Functions signature should include value, ... and possibly content_type, filename. Other parameters may be provided if you want to use the headers from webutils::parse_multipart().

Parser function structure is something like below.

parser <- function(parser_arguments_here) {
# return a function to parse a raw value
function(value, ...) {
# do something with raw value
}
}

## Functions

• registered_parsers: Return all registered parsers

## Examples

# content-type header is mostly used to look up charset and adjust encoding
parser_dcf <- function(...) {
function(value, content_type = "text/x-dcf", ...) {
charset <- getCharacterSet(content_type)
value <- rawToChar(value)
Encoding(value) <- charset
if (FALSE) register_parser("dcf", parser_dcf, fixed = "text/x-dcf")