haskell-servant / servant

Servant is a Haskell DSL for describing, serving, querying, mocking, documenting web applications and more!
https://docs.servant.dev/
1.83k stars 413 forks source link

Is there any way to use servant-client with blaze-html #1379

Open jkaye2012 opened 3 years ago

jkaye2012 commented 3 years ago

Hi all,

I would like to use servant-client to generate the clients for unit testing my server. I have most things working, but have run up against a similar issue to the one mentioned here: https://github.com/haskell-servant/servant-lucid/issues/14

I've attempted to implement my own MimeUnrender instance, but this is problematic because the "standard" blaze-html type is MarkupM (), meaning that text beneath the HTML has been lost.

Is there any way to get this working without resorting to an entirely different client library? This solution does not necessarily have to be something implemented within one of these libraries, I would be happy implementing something on my end as well, though I would ideally not have to change my server-side code to satisfy idiosyncracies of the client.

Thanks, Jordan

jkaye2012 commented 3 years ago

There is at least one solution to this problem:

instance MimeUnrender HTML Markup where
  mimeUnrender _ val = Right $ Content (ByteString $ toStrict val) ()

Of course, I don't think this is necessarily a great solution, but used in combination with an HTML parsing library of some sort, this would at least allow users to read HTML content using servant-client (I don't believe this is possible at all currently, please correct me if I'm wrong!).