Safe Haskell | None |
---|---|
Language | Haskell2010 |
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
- type Query = [QueryItem]
- type QueryItem = (ByteString, Maybe ByteString)
- maybeKey :: String -> Maybe String -> Query
- makeKey :: String -> String -> Query
- makeItem :: String -> String -> QueryItem
- (+/+) :: String -> String -> String
- webAPIQuery :: (MonadIO m, FromJSON a) => String -> Query -> m a
- lookupKey :: FromJSON a => Text -> Object -> Maybe a
- lookupKeyEither :: FromJSON a => Text -> Object -> Either String a
- lookupKey' :: FromJSON a => Text -> Object -> a
Documentation
(+/+) :: 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"
:: (MonadIO m, FromJSON a) | |
=> String | url of endpoint |
-> Query | query options |
-> m a | returned json |
Low-level web api query
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