http-query-0.1.0.1: Simple http queries
Safe HaskellNone
LanguageHaskell2010

Network.HTTP.Query

Description

A small library for querying a Web API.


import Data.Text.IO as T
import Network.HTTP.Query

main = do
  let api = "http://www.example.com/api/1"
      endpoint = api +/+ "search"
  res <- webAPIQuery endpoint $ makeKey "q" "needle"
  T.putStrLn $
    case lookupKey "results" res of
      Nothing ->
        fromMaybe "search failed" $ lookupKey "error" res
      Just results ->
        lookupKey' "location" results
Synopsis

Documentation

type Query = [QueryItem] #

type QueryItem = (ByteString, Maybe ByteString) #

maybeKey :: String -> Maybe String -> Query Source #

Maybe create a query key

makeKey :: String -> String -> Query Source #

Make a singleton key-value Query

makeItem :: String -> String -> QueryItem Source #

Make a key-value QueryItem

(+/+) :: String -> String -> String infixr 5 Source #

Combine two path segments with a slash

"abc" +/+ "def" == "abc/def"
"abc/" +/+ "def" == "abc/def"
"abc" +/+ "/def" == "abc/def"

webAPIQuery Source #

Arguments

:: (MonadIO m, FromJSON a) 
=> String

url of endpoint

-> Query

query options

-> m a

returned json

Low-level web api query

lookupKey :: FromJSON a => Text -> Object -> Maybe a Source #

Look up key in object

lookupKeyEither :: FromJSON a => Text -> Object -> Either String a Source #

Like lookupKey but returns error message if not found

lookupKey' :: FromJSON a => Text -> Object -> a Source #

Like lookupKey but raises an error if no key found