How to deal with variable/dynamic content-type

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to deal with variable/dynamic content-type

Josejuan Pi
Hello,

I'm impressed with elegance and easily of Servant and I'm using it on my current personal project.

On my service, users can send and get resources (files) from any content-type. They send resources with some like

   ... :> Files :> Post '[JSON] (Result ())

I read files from any content-type successfully. My problem is taking back that resources to the user. Currently works fine fixing to OctetStream (or many others)

    ...  :> Get '[OctetStream] MyResource

But really, each resource has their own content-type (and I cannot convert between them or ensure that).

Ideally, many problems will be solved if I can write something like

    data OracleContentType

    instance Accept OracleContentType where
        contentType _ = getMyResourceContentType myRes -- Bang!

    instance MimeRender OracleContentType MyResource where
        mimeRender _ myRes = getMyResourceData myRes

obviously it not works. I suppose can down to Wai like serveDirectory is doing but I wish use my current monad stack (my current resource endpoint here). Exists some convenient way to do it?

Thank you!










--