on master help sign in
Update the examples in Haddocks to use ‘runReq’
commitbf724140319762623bfae5eac50a81360f237dd4 authormrkkrp <markkarpov92@gmail.com> dateTue 9 Jan 2018, 17:04 (9 years ago) parentc3e6cfe
1 file changed+12−14
Network/HTTP/Req.hs+12−14
Network/HTTP/Req.hs+12−14
@@ -311,41 +311,39 @@ import GHC.Exts (Constraint)
311311-- >
312312-- > module Main (main) where
313313-- >
314−-- > import Control.Exception (throwIO)
315314-- > import Control.Monad
315+-- > import Control.Monad.IO.Class
316316-- > import Data.Aeson
317+-- > import Data.Default.Class
317318-- > import Data.Maybe (fromJust)
318319-- > import Data.Monoid ((<>))
319320-- > import Data.Text (Text)
320321-- > import GHC.Generics
321322-- > import Network.HTTP.Req
322323-- > import qualified Data.ByteString.Char8 as B
323−-- >
324−-- > instance MonadHttp IO where
325−-- > handleHttpException = throwIO
326324--
327325-- We will be making requests against the <https://httpbin.org> service.
328326--
329327-- Make a GET request, grab 5 random bytes:
330328--
331329-- > main :: IO ()
332−-- > main = do
330+-- > main = runReq def $ do
333331-- > let n :: Int
334332-- > n = 5
335333-- > bs <- req GET (https "httpbin.org" /: "bytes" /~ n) NoReqBody bsResponse mempty
336−-- > B.putStrLn (responseBody bs)
334+-- > liftIO $ B.putStrLn (responseBody bs)
337335--
338336-- The same, but now we use a query parameter named @\"seed\"@ to control
339337-- seed of the generator:
340338--
341339-- > main :: IO ()
342−-- > main = do
340+-- > main = runReq def $ do
343341-- > let n, seed :: Int
344342-- > n = 5
345343-- > seed = 100
346344-- > bs <- req GET (https "httpbin.org" /: "bytes" /~ n) NoReqBody bsResponse $
347345-- > "seed" =: seed
348−-- > B.putStrLn (responseBody bs)
346+-- > liftIO $ B.putStrLn (responseBody bs)
349347--
350348-- POST JSON data and get some info about the POST request:
351349--
@@ -358,27 +356,27 @@ import GHC.Exts (Constraint)
358356-- > instance FromJSON MyData
359357-- >
360358-- > main :: IO ()
361−-- > main = do
359+-- > main = runReq def $ do
362360-- > let myData = MyData
363361-- > { size = 6
364362-- > , color = "Green" }
365363-- > v <- req POST (https "httpbin.org" /: "post") (ReqBodyJson myData) jsonResponse mempty
366−-- > print (responseBody v :: Value)
364+-- > liftIO $ print (responseBody v :: Value)
367365--
368366-- Sending URL-encoded body:
369367--
370368-- > main :: IO ()
371−-- > main = do
369+-- > main = runReq def $ do
372370-- > let params =
373371-- > "foo" =: ("bar" :: Text) <>
374372-- > queryFlag "baz"
375373-- > response <- req POST (https "httpbin.org" /: "post") (ReqBodyUrlEnc params) jsonResponse mempty
376−-- > print (responseBody response :: Value)
374+-- > liftIO $ print (responseBody response :: Value)
377375--
378376-- Using various optional parameters and URL that is not known in advance:
379377--
380378-- > main :: IO ()
381−-- > main = do
379+-- > main = runReq def $ do
382380-- > -- This is an example of what to do when URL is given dynamically. Of
383381-- > -- course in a real application you may not want to use 'fromJust'.
384382-- > let (url, options) = fromJust (parseUrlHttps "https://httpbin.org/get?foo=bar")
@@ -388,7 +386,7 @@ import GHC.Exts (Constraint)
388386-- > basicAuth "username" "password" <>
389387-- > options <> -- contains the ?foo=bar part
390388-- > port 443 -- here you can put any port of course
391−-- > print (responseBody response :: Value)
389+-- > liftIO $ print (responseBody response :: Value)
392390
393391req
394392 :: ( MonadHttp m