trasa-client 0.3 → 0.4
raw patch · 3 files changed
+67/−157 lines, 3 filesdep −aesondep −ipdep −trasa-clientdep ~containersdep ~http-clientdep ~http-typesnew-uploader
Dependencies removed: aeson, ip, trasa-client, unordered-containers
Dependency ranges changed: containers, http-client, http-types, text, trasa
Files
- LICENSE +5/−17
- test/Main.hs +0/−99
- trasa-client.cabal +62/−41
LICENSE view
@@ -1,20 +1,8 @@-Copyright (c) 2017 Kyle McKean+Copyright 2017-2019 Andrew Martin+Copyright 2017-2019 Kyle McKean -Permission is hereby granted, free of charge, to any person obtaining-a copy of this software and associated documentation files (the-"Software"), to deal in the Software without restriction, including-without limitation the rights to use, copy, modify, merge, publish,-distribute, sublicense, and/or sell copies of the Software, and to-permit persons to whom the Software is furnished to do so, subject to-the following conditions:+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included-in all copies or substantial portions of the Software.+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.-IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY-CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,-TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE-SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
− test/Main.hs
@@ -1,99 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE InstanceSigs #-}-{-# LANGUAGE LambdaCase #-}-{-# LANGUAGE DeriveGeneric #-}-{-# LANGUAGE DeriveAnyClass #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE KindSignatures #-}-{-# LANGUAGE TypeFamilies #-}-{-# OPTIONS_GHC -Wall -Werror -Wno-unticked-promoted-constructors #-}-module Main where--import Data.Kind (Type)-import GHC.Generics hiding (Meta)-import Data.Bifunctor (Bifunctor(..))-import qualified Data.HashMap.Strict as H-import qualified Data.Text as T-import Data.Aeson- (Value(..),FromJSON(..),ToJSON(..),encode,eitherDecode'- ,object,withObject,(.:),(.=))-import Net.Types (IPv4)-import Control.Exception (catch,SomeException)-import System.Exit (exitFailure)-import qualified Network.HTTP.Types.Status as N-import qualified Network.HTTP.Client as N-import Trasa.Core-import Trasa.Core.Implicit-import qualified Trasa.Method as M-import Trasa.Client-import Trasa.Client.Implicit--data Ip = Ip- { origin :: IPv4- } deriving (Generic,FromJSON,ToJSON)--instance Show Ip where- show (Ip ipv4) = "{ origin: " ++ show ipv4 ++ " }"--data Args = Args- { args :: H.HashMap T.Text Value- } deriving Show--instance FromJSON Args where- parseJSON = withObject "Args" $ \o -> Args <$> o .: "args"--instance ToJSON Args where- toJSON (Args as) = object [ "args" .= as ]--bodyAeson :: (FromJSON a, ToJSON a) => BodyCodec a-bodyAeson = BodyCodec (pure "application/json") encode (first T.pack . eitherDecode')--int :: CaptureCodec Int-int = showReadCaptureCodec--bodyUnit :: BodyCodec ()-bodyUnit = BodyCodec (pure "text/html") (const "") (const (Right ()))--data Route :: [Type] -> [Param] -> Bodiedness -> Type -> Type where- RouteHome :: Route '[] '[] Bodyless ()- RouteIp :: Route '[] '[] Bodyless Ip- RouteStatus :: Route '[Int] '[] Bodyless ()- RouteQuery :: Route '[] '[Optional Int] Bodyless Args--instance HasMeta Route where- type CaptureStrategy Route = CaptureCodec- type QueryStrategy Route = CaptureCodec- type RequestBodyStrategy Route = Many BodyCodec- type ResponseBodyStrategy Route = Many BodyCodec- meta :: Route caps qrys req resp -> MetaCodec caps qrys req resp- meta route = metaBuilderToMetaCodec $ case route of- RouteHome -> Meta end qend bodyless (resp bodyUnit) M.get- RouteIp -> Meta (match "ip" ./ end) qend bodyless (resp bodyAeson) M.get- RouteStatus -> Meta (match "status" ./ capture int ./ end) qend bodyless (resp bodyUnit) M.get- RouteQuery -> Meta (match "anything" ./ end) (optional "int" int .& qend) bodyless (resp bodyAeson) M.get--shouldRight :: Show resp => Config -> Prepared Route resp -> IO ()-shouldRight conf route = do- putStr $ show (link route) ++ ": "- client conf route >>= \case- Left err -> do- print err- exitFailure- Right val -> print val--main :: IO ()-main = do- manager <- N.newManager N.defaultManagerSettings- let conf = Config (Authority Http "httpbin.org" Nothing) mempty manager- res <- catch (client conf (prepare RouteHome)) $ \(_ :: SomeException) -> return (Left (status N.status400))- case res of- Left err -> do- putStrLn "Could not connect to httpbin.org, not running test suite"- putStrLn ("Could not connect because: " ++ show err)- Right _ -> do- putStrLn "Connected to httpbin.org, actually testing routes now..."- shouldRight conf (prepare RouteIp)- shouldRight conf (prepare RouteStatus 200)- shouldRight conf (prepare RouteQuery (Just 1))
trasa-client.cabal view
@@ -1,47 +1,68 @@-name: trasa-client-version: 0.3-synopsis: Type safe http requests-license: MIT-license-file: LICENSE-author: Kyle McKean-maintainer: mckean.kylej@gmail.com-copyright: @2017 Kyle McKean-category: Web-build-type: Simple-cabal-version: >=1.10-description: Http client integration for trasa+cabal-version: 2.2+name:+ trasa-client+version:+ 0.4+synopsis:+ Type safe http requests+description:+ http-client integration for trasa+homepage:+ https://github.com/haskell-trasa/trasa+author:+ Andrew Martin+ Kyle McKean+maintainer:+ Andrew Martin <andrew.thaddeus@gmail.com>+ Kyle McKean <mckean.kylej@gmail.com>+ chessai <chessai1996@gmail.com>+license:+ MIT+license-file:+ LICENSE+copyright:+ © 2017-2019 Andrew Martin+ © 2017-2019 Kyle McKean+category:+ Web+build-type:+ Simple library- exposed-modules: Trasa.Client- , Trasa.Client.Implicit- build-depends: base >= 4.9 && < 5- , bytestring == 0.10.*- , binary == 0.8.*- , text == 1.2.*- , containers >= 0.5- , case-insensitive == 1.2.*- , http-types >= 0.9- , http-media >= 0.6 && < 0.8- , http-client == 0.5.*- , trasa == 0.3.*- hs-source-dirs: src- default-language: Haskell2010+ hs-source-dirs:+ src+ exposed-modules:+ Trasa.Client+ Trasa.Client.Implicit+ build-depends:+ , base >= 4.9 && < 5+ , binary == 0.8.*+ , bytestring == 0.10.*+ , case-insensitive == 1.2.*+ , containers >= 0.5 && < 0.7+ , http-client == 0.5.*+ , http-media >= 0.6 && < 0.8+ , http-types >= 0.9+ , text == 1.2.*+ , trasa == 0.4.*+ default-language:+ Haskell2010 -test-suite test- type: exitcode-stdio-1.0- hs-source-dirs: test- main-is: Main.hs- build-depends: base >= 4.9 && < 5- , trasa- , trasa-client- , http-types- , http-client- , unordered-containers- , text- , ip- , aeson- ghc-options: -threaded -rtsopts -with-rtsopts=-N- default-language: Haskell2010+--test-suite test+-- type: exitcode-stdio-1.0+-- hs-source-dirs: test+-- main-is: Main.hs+-- build-depends: base >= 4.9 && < 5+-- , trasa+-- , trasa-client+-- , http-types+-- , http-client+-- , unordered-containers+-- , text+-- , ip+-- , aeson+-- ghc-options: -threaded -rtsopts -with-rtsopts=-N+-- default-language: Haskell2010 source-repository head type: git