rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.39k stars 256 forks source link

Multi serializers support with request headers #793

Open meztez opened 3 years ago

meztez commented 3 years ago

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

atheriel commented 3 years ago

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.