getLocationById
:: Integer
-> ClientM (Envelope '[InvalidLocationError, NoSuchLocationError] Location)
getLocationById = client api
main :: IO ()
main = do
manager <- newManager defaultManagerSettings
let env = mkClientEnv manager baseUrl
print =<< runClientM program env
program :: ClientM ()
program = do
liftIO $ putStrLn "Enter the ID of a location (non-negative integer):"
locationId <- liftIO readLn
result <- getLocationById locationId
liftIO $ do
putStrLn "Result:"
putStrLn $ catchesEnvelope (show, show) show result
Enter the ID of a location (non-negative integer):
0
Result:
Location {locationId = 0, locationName = "Amsterdam"}
Right ()
Enter the ID of a location (non-negative integer):
-1
Left (FailureResponse (Response {responseStatusCode = Status {statusCode = 400, statusMessage = "Bad Request"}, responseHeaders = fromList [("Transfer-Encoding","chunked"),("Date","Wed, 13 Feb 2019 01:47:56 GMT"),("Server","Warp/3.2.26"),("Content-Type","application/json;charset=utf-8")], responseHttpVersion = HTTP/1.1, responseBody = "{\"err\":[]}"}))