Skip to content

Instantly share code, notes, and snippets.

@deckool
Forked from owainlewis/Example.hs
Created October 27, 2013 11:01
Show Gist options
  • Save deckool/7180441 to your computer and use it in GitHub Desktop.
Save deckool/7180441 to your computer and use it in GitHub Desktop.
-- The lack of documentation for these things is crazy
module HTTPExamples
where
import Network.HTTP
import Control.Applicative
url = "http://www.owainlewis.com"
-- Fetch a URL via GET
fetch :: String -> IO String
fetch url = do
response <- simpleHTTP (getRequest url)
body <- getResponseBody response
return body
-- Fetch n chars from a url
fetch_chunk :: String -> Int -> IO [Char]
fetch_chunk url n =
simpleHTTP (getRequest url) >>=
fmap (take n) . getResponseBody
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment