Skip to content

Instantly share code, notes, and snippets.

@MarkJr94
Last active December 31, 2015 10:49
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 MarkJr94/7975626 to your computer and use it in GitHub Desktop.
Save MarkJr94/7975626 to your computer and use it in GitHub Desktop.
import Network.HTTP.Conduit
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.UTF8 as BU
import qualified Data.ByteString.Lazy.UTF8 as LU
import qualified Data.Text as T
import Data.Conduit
import qualified Data.Conduit.List as CL
import qualified Data.Conduit.Binary as CB
import System.IO
sink = undefined
main = do
request <- parseUrl "http://www.reddit.com/user/urdnot_rekt/comments.json"
let req = request { queryString = BU.fromString "limit=100" }
withManager $ \manager -> do
response <- http req manager
let body = responseBody response
body $$+- CB.sinkHandle stdout
-- body $$+- sink
@mxswd
Copy link

mxswd commented Dec 16, 2013

SPOILERS














import qualified Data.Aeson as J

comments :: IO (Maybe J.Value)
comments = do
    request <- parseUrl "http://www.reddit.com/user/urdnot_rekt/comments.json"
    let req = request { queryString = BU.fromString "limit=100" }
    js <- withManager $ \manager -> do
        response <- http req manager
        let body = responseBody response
        body $$+- CB.sinkLbs
    return $ J.decode js

Then try to make a data type to represent the API, such as Comment, then change the J.Value to your data type.

http://hackage.haskell.org/package/aeson-0.6.2.1/docs/Data-Aeson.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment