plumber icon indicating copy to clipboard operation
plumber copied to clipboard

Multi serializers support with request headers

Open meztez opened this issue 3 years ago • 1 comments

What about allowing to register multiple serializers ,like parsers.

#* Return a data frame of random values #* @param n size of data frame #* @get /random_df #* @serializer csv #* @serializer json #* @serializer rds handler Default behaviour would be to use the first one in the dict but we could use accept header like github does to select a different serializer. Plus it would not require a lot of code modification I believe. Would probably have to fiddle a bit with open api/spec to facilitate headers handling.

See https://community.rstudio.com/t/switching-plumber-serialization-type-based-on-url-arguments/98535/6

meztez avatar Apr 09 '21 15:04 meztez

I've considered something like this in the past. Correctness would dictate that Plumber return HTTP 406 if the Accept header does not contain a content type it can produce. However, in practice many clients will not set the Accept header correctly. If that is the case, you'll need some way to indicate the default serializer.

atheriel avatar Apr 19 '21 13:04 atheriel