I am trying to use Wai and Warp to write a modest HTTP server and I am stuck trying to read POST/PUT request's bodies to extract form parameters. When I do the following
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai.Handler.Warp (run)
import qualified Data.ByteString.Char8 as C
import Network.Wai.Parse (parseRequestBody, lbsSink)
import Network.Wai(Response(..))
import Network.HTTP.Types(status200)
import Blaze.ByteString.Builder
main = run 3000 app
app req = do
(params, _) <- parseRequestBody lbsSink req
let r = C.concat $ map (\(x,y) -> C.concat [x,y]) params
return $ ResponseBuilder
status200
[("Content-Type", "text/plain")]
$ fromByteString r
and then I try a simple request like
curl -o - -X POST http://localhost:3000/ -d name=toto
it appears my parameters don't get passed to other server, or rather do not get decoded properly as nothing is returned.