{-# LANGUAGE OverloadedStrings #-}

import

Network.HTTP.Conduit

-- the main module

-- The streaming interface uses conduits

import

Data.Conduit

import

Data.Conduit.Binary

import

qualified

Data.ByteString.Lazy

as

L

import

Control.Monad.IO.Class

main

IO

main

do

-- Simplest query: just download the information from the given URL as a

-- lazy ByteString.

"http://www.example.com/foo.txt"

L.

"foo.txt"

-- Use the streaming interface instead. We need to run all of this inside a

-- ResourceT, to ensure that all our connections get properly cleaned up in

-- the case of an exception.

do

-- We need a Manager, which keeps track of open connections. simpleHttp

-- creates a new manager on each run (i.e., it never reuses

-- connections).

-- A more efficient version of the simpleHttp query above. First we

-- parse the URL to a request.

"http://www.example.com/foo.txt"

-- Now get the response

-- And finally stream the value to a file

"foo.txt"

-- Make it a POST request, don't follow redirects, and accept any

-- status code.

let

"POST"

0

Nothing

"post-foo.txt"