rexyai / RestRserve

R web API framework for building high-performance microservices and app backends
https://restrserve.org
276 stars 32 forks source link

Question: content type zip / binary -> application/zip, application/octet-stream #185

Closed Andreas4242 closed 2 years ago

Andreas4242 commented 2 years ago

Hi

thank you very much for making this project available!

Is it possible to serve gzip objects? I could not find a default content handler for this in the code or examples. Basically something like

application/zip, application/octet-stream

Thank you in advance, BR Andreas

Andreas4242 commented 2 years ago

Ok I seem have found the solution in the doku:

In order to resolve problem above we would need to either register application/x-rds content handler with ContentHandlers$set_encode() or manually specify encode function (identity in our case):

application$add_get(path = "/factorial-rds2", function(.req, .res) {
  x = as.integer(.req$get_param_query("x"))
  result = factorial(x)
  body_rds = serialize(list(result = result), connection = NULL)
  .res$set_body(body_rds)
  .res$set_content_type("application/x-rds")
  .res$encode = identity
})