haskell-servant / servant

Servat 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

XML Content Types #711

Closed ivan-m closed 6 years ago

ivan-m commented 7 years ago

At the top of Servant.API.ContentTypes the Haddock documentation references an example usage of an XML content type.

Does such an instance exist (or did so in the past)? The only other mention of XML I can find is in generation of Markdown documentation.

phadej commented 7 years ago

AFAIK there isn't. It's simple to add, see e.g. http://hackage.haskell.org/package/servant-lucid-0.7.1/docs/src/Servant-HTML-Lucid.html, but one have to find a library doing all the heavy lifting, i.e. xml serialization (and parsing).

EDIT obviously you could (ab)use blaze or lucid to write XML documents...

ivan-m commented 7 years ago

That's what I thought; the closest I've come across is HXT's Pickling support, but it's typeclass is very limited in terms of data types covered (and with no in-built Generics/DefaultSignatures support either, making instances more verbose).

fizruk commented 7 years ago

We use xml-picklers for our very limited use of XML (together with xml-conduit, xml-conduit-writer and xml-types).

phadej commented 7 years ago

xml-picklers doesn't seem to provide type-classes to do conversions, do you have your own, @fizruk? Does it make sense to create servant-xml-picklers ?

fizruk commented 7 years ago

@phadej no, we provide per-type MimeUnrender XML instances, which is ok, since we only have a few types. I can't say much about servant-xml-picklers — we don't really use XML much, so I can't say where others' needs are.

ivan-m commented 7 years ago

If I were to write servant-xml-picklers, would it be worth putting a type class (+ instances) into that library or trying to get one upstream?

ivan-m commented 7 years ago

(My interest in this is I have to write a server to receive data from a third party that are only starting to consider using this new-fangled JSON technology and thus want to provide XML data, even though it's simple enough to be JSON.)

phadej commented 7 years ago

@ivan-m It depends. As you, I'd start small and implement everything needed in your app. With experience it's much easier to make design decisions, what works and what not. Sorry, but you are a bit on your own with XML stuff.

fosskers commented 6 years ago

Am I late to the party? Here's some simple XML support: https://hackage.haskell.org/package/servant-xml

alpmestan commented 6 years ago

@fosskers There's no such thing as being late to the servant party... whatever that means.

Cheers for putting that package together. Feel free (if you want to) to send PRs to the tutorial or cookbook etc if you want to document this library further (e.g a cookbook recipe about dealing with XML in request/response bodies?) as well as I guess make it a little more discoverable.

jkarni commented 6 years ago

Should we close this issue?

On Tue, Mar 6, 2018 at 9:43 AM, Alp Mestanogullari <notifications@github.com

wrote:

@fosskers https://github.com/fosskers There's no such thing as being late to the servant party... whatever that means.

Cheers for putting that package together. Feel free (if you want to) to send PRs to the tutorial or cookbook etc if you want to document this library further (e.g a cookbook recipe about dealing with XML in request/response bodies?) as well as I guess make it a little more discoverable.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/haskell-servant/servant/issues/711#issuecomment-370706156, or mute the thread https://github.com/notifications/unsubscribe-auth/ABlKmv9PRkb_B42Dy6gyrzZyWkpAdlHXks5tbkw8gaJpZM4Mb-lz .

ivan-m commented 6 years ago

The limitation of this library is that it only supports MimeRender, not MimeUnrender.

However, I ended up implementing my own internal library (I thought about publishing it but it has a rather severe limitation on sum-types and works solely for my simple use-cases) based upon xml-conduit. As such, I'm happy to close this issue.

alpmestan commented 6 years ago

We can close it in that we have at least one solution out there. This should definitely not stop any author of xml<->servant packages to advertise their solution, either/both here and somewhere in the docs, IMO.

fosskers commented 6 years ago

The limitation of this library is that it only supports MimeRender, not MimeUnrender.

At least for the first release I followed the model of Servant.HTML.Lucid. Luckily xmlbf does also have a FromXml typeclass, so I could add support for MimeUnrender. Do people send XML in request bodies?

fosskers commented 6 years ago

I updated servant-xml to include a MimeUnrender instance.