使用http-enumerator的http PUT请求

时间:2011-05-20 13:15:58

标签: haskell

我想使用http-enumerator包不仅可以执行GET / POST,还可以执行PUT。

HTTP的枚举:
http://hackage.haskell.org/package/http-enumerator
http://hackage.haskell.org/packages/archive/http-enumerator/0.6.5/doc/html/Network-HTTP-Enumerator.html

*)我的第一步是构建一个请求并打印出来 但是我没有写出一个合适的Show函数(错误“没有Show for Show ..因使用print而出现”)。

*)接下来我想我必须使用函数“httpLbs :: MonadIO m => Request m - > Manager - > m Response”来获取响应。

对于那些搜索并需要该信息的人:haskell,REST或restful request,http,rest api access

1 个答案:

答案 0 :(得分:5)

http-enumerator / http-conduit并不关心你是否正在使用POST,PUT,DELETE等。你只需要更改method数据类型的Request记录。您最好的选择是依靠OverloadedStrings,例如:

{-# LANGUAGE OverloadedStrings #-}
import Network.HTTP.Enumerator

main = do
    req <- parseUrl "http://www.example.com/put-url"
    withManager $ httpLbs req { method = "PUT" }

HTH