[web-devel] Examples and/or tutorials for WAI

Michael Snoyman michael at snoyman.com
Mon Feb 7 06:29:05 CET 2011

On Mon, Feb 7, 2011 at 7:23 AM, Thomas Sutton <thsutton at gmail.com> wrote:
> Hi All,
> I spent a few hours last night trying to hook a HaXR XML-RPC server up
> with WAI instead of using the built-in CGI support. Alas, I failed
> dismally. Is there any more thorough tutorial-style documentation for
> WAI? Or a good example project that does something more sophisticated
> than "Hello, Web!"?
> What tripped me up was trying to figure out the enumerator part of the
> API so that I can read the request body (and turn it into a String)
> and run the XML-RPC request handler. Any help would be appreciated!

There's no tutorial on WAI at the moment. You could look at the code
in yesod-core to get an idea of how to use it, but I doubt that will
give you much of a return on your investment. In the future, I intend
to add a nice explanation of WAI to the Yesod book, but I'm not there

As for your specific issue: if you don't mind reading the entire
request body into memory, you can get a lazy bytestring fairly easily
using the consume[1] function from the enumerator package. Converting
that into a String depends on your character encoding.

If you're looking to do *lazy* IO... that's a bit more complicated,
and will necessarily involve some hacks, but it is possible. I'll
likely be writing that kind of code in the not-too-distant future, so
let me know if you're interested in that. Also, if you can think of
specific examples you would like to see, let me know and I can try to
add them to the repo.


[1] http://hackage.haskell.org/packages/archive/enumerator/0.4.6/doc/html/Data-Enumerator-Binary.html#v:consume

More information about the web-devel mailing list