Skip to content

Instantly share code, notes, and snippets.

@douglarek
Forked from owainlewis/Example.hs
Created March 29, 2014 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douglarek/9855105 to your computer and use it in GitHub Desktop.
Save douglarek/9855105 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