Design of Webmachine in Haskell

Hi, I would love to create a port of Webmachine [1] in Haskell so I can learn the language and in the meanwhile create something useful. The problem is, I don't know how I would design such a system in Haskell. Simply put, webmachine is a library in Erlang which let's you create a REST API by binding resources to URI's. The resources have sane defaults, defined with functions, like `resource_exists`, `service_available` and `is_authorized`. You can override these functions per resource to create your own API. Webmachine will then create the appropriate response when a request comes in. I have been thinking how to implement such a system in Haskell, and I have come up with the following. First of, use WAI with Warp to handle the `Request` -> `Response` cycle. That was easy to come up with, but I'm still struggling with the following question: What would a `Resource` be in Haskell? I need something that lets me define sane defaults which I can override per resource. Should I have a `Resource` typeclass which defines all the default functions? Or is there a better way to accomplish this? I hope the above was a bit clear, would appreciate any insights! [1]: http://wiki.basho.com/Webmachine-Resource.html -- Petar Radosevic | @wunki

On Sat, Apr 14, 2012 at 7:38 PM, Petar Radosevic
Hi,
I would love to create a port of Webmachine [1] in Haskell so I can learn the language and in the meanwhile create something useful. The problem is, I don't know how I would design such a system in Haskell.
Simply put, webmachine is a library in Erlang which let's you create a REST API by binding resources to URI's. The resources have sane defaults, defined with functions, like `resource_exists`, `service_available` and `is_authorized`. You can override these functions per resource to create your own API. Webmachine will then create the appropriate response when a request comes in.
I have been thinking how to implement such a system in Haskell, and I have come up with the following. First of, use WAI with Warp to handle the `Request` -> `Response` cycle. That was easy to come up with, but I'm still struggling with the following question: What would a `Resource` be in Haskell? I need something that lets me define sane defaults which I can override per resource. Should I have a `Resource` typeclass which defines all the default functions? Or is there a better way to accomplish this?
I hope the above was a bit clear, would appreciate any insights!
[1]: http://wiki.basho.com/Webmachine-Resource.html -- Petar Radosevic | @wunki
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
Hi Petar, When I was at QCon, I heard a talk from Steve Vinoski on Webmachine, and I was surprised to hear how close webmachine was to Haskell already, The concept is basically sticking a state monad on top of WAI. My guess is you would want to use a record type for a Resource, not a typeclass, to make it easier to swap out behaviors. But honestly, I haven't given this any thought since I saw the presentation 6 months ago. Michael

Hi Michael,
Michael Snoyman
When I was at QCon, I heard a talk from Steve Vinoski on Webmachine, and I was surprised to hear how close webmachine was to Haskell already, The concept is basically sticking a state monad on top of WAI. My guess is you would want to use a record type for a Resource, not a typeclass, to make it easier to swap out behaviors. But honestly, I haven't given this any thought since I saw the presentation 6 months ago.
Thanks for your insight, I didn't even consider using record types for a resource. Will also read up upon state monads. I believe that Webmachine passes a dictionary to every function in the HTTP graph[1]. Do you see the state monad having this purpose? [1]: https://bitbucket.org/justin/webmachine/wiki/BigHTTPGraph -- Petar Radosevic | @wunki

On Mon, Apr 16, 2012 at 6:05 PM, Petar Radosevic
Hi Michael,
Michael Snoyman
writes: When I was at QCon, I heard a talk from Steve Vinoski on Webmachine, and I was surprised to hear how close webmachine was to Haskell already, The concept is basically sticking a state monad on top of WAI. My guess is you would want to use a record type for a Resource, not a typeclass, to make it easier to swap out behaviors. But honestly, I haven't given this any thought since I saw the presentation 6 months ago.
Thanks for your insight, I didn't even consider using record types for a resource. Will also read up upon state monads. I believe that Webmachine passes a dictionary to every function in the HTTP graph[1]. Do you see the state monad having this purpose?
[1]: https://bitbucket.org/justin/webmachine/wiki/BigHTTPGraph -- Petar Radosevic | @wunki
IIRC, each function is passed a dictionary and returns a new dictionary. That's the very essence of a state monad, which is why it could be such a perfect fit here. Of course, I may *not* be remembering correctly. Michael
participants (2)
-
Michael Snoyman
-
Petar Radosevic