First of all I'm quite new to Haskell - but I must say I've fallen in love with the language since I started playing with it. I've done extensive C, Java, python and perl. Haskell is definitely growing on me. I've written a web application/services in perl/python for one of my personal projects a while back - I was wondering if I can move it to haskell as a fun project and do some haskell hackery to see how it evolves.
I know there are some outstanding frameworks for web applications in haskell. What I'd like to do is have a service written in haskell that will respond with data in different formats (SOAP, REST-xml, REST-json). I'd use javascript to build DOM etc. So my question is are there any libraries that I could use to convert the format of the data on the fly already? Or given the scenario how would you go about doing it in haskell?
I haven't played with this project since 2008, and my initial thought was to use apacheCXF from java community and code it all in java. But I would love to do it in haskell. Any hints please?
I have written something similar using Happstack.
What I did was create a type to represent all the possible responses of my web application.
data AppResponse = Foo String Int | Bar [String] | etc
then wrote my handlers to return values of this type:
home :: ServerPart AppResponse
user :: UserId -> ServerPart AppResponse
etc,
Then I wrote functions that would render the response in different formats:
jsonResponse :: AppResponse -> JSON
xmlResponse :: AppResponse -> XML
etc.
Then there is a simple filter that looks at the Accept
header and decides which of those conversion functions to use.
This approach is nice because:
newFormatResponse :: AppResponse -> NewFormat
. The AppResponse
type details every possible response, so you don't have to hunt all over the code figuring out what responses are even possible.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With