packages feed

webapi 0.1.0.0 → 0.2.0.0

raw patch · 4 files changed

+19/−6 lines, 4 filesdep ~aesondep ~vector

Dependency ranges changed: aeson, vector

Files

src/WebApi/Contract.hs view
@@ -5,7 +5,7 @@ Stability   : experimental  Provides the contract for the web api. The contract consists of 'WebApi' and 'ApiContract' classes.-'WebApi' contains information related to the entire group of APIs whereas 'ApiContract' is concerned with information related to each end point. Once the contract is written, it can be then used to+'WebApi' contains information related to the entire group of endpoints whereas 'ApiContract' is concerned with information related to each end point. Once the contract is written, it can be then used to  * Write a 'WebApiImplementation' and corresponding 'ApiHandler' for it. * Get a client for web api.@@ -22,6 +22,7 @@ {-# LANGUAGE MultiParamTypeClasses     #-} {-# LANGUAGE PolyKinds                 #-} {-# LANGUAGE TypeFamilies              #-}+{-# LANGUAGE UndecidableInstances      #-} module WebApi.Contract        (-- * API Contract          WebApi (..)
src/WebApi/Router.hs view
@@ -157,11 +157,14 @@   MarkDyn (p1 :/ t) = (p1 :/ t)   MarkDyn (t :: *)   = DynamicPiece t -instance (Router s r '(m, '[]), SingMethod m) => Router s (Route (m ': ms) r) pr where-  route _ _s _ request respond =+instance ( SingMethod m+         , Router s r '(m, '[])+         , Router s (Route ms r) pr) => +         Router s (Route (m ': ms) r) pr where+  route _ _s parsedRoute request respond =     case requestMethod request == meth of       True  -> route (Proxy :: Proxy r) _s (Nil (Proxy :: Proxy m)) request respond-      False -> respond NotMatched+      False -> route (Proxy :: Proxy (Route ms r)) _s parsedRoute request respond     where meth = singMethod (Proxy :: Proxy m)  instance Router s (Route '[] r) pr where
tests/WebApi/RequestSpec.hs view
@@ -76,6 +76,7 @@                                    , TRACE                                    , CONNECT                                    , (CUSTOM ("TEST"))+                                   , OPTIONS                                    ] ApiR                           ] @@ -142,6 +143,9 @@   -- type FormParam (CUSTOM "TEST") ApiR  = FoP   type ApiOut (CUSTOM "TEST") ApiR     = () +instance ApiContract ReqSpec OPTIONS ApiR where+  type ApiOut OPTIONS ApiR = [Text]+ instance ApiHandler ReqSpecImpl (CUSTOM "TEST") ApiR where   handler _ _ = respond () instance ApiHandler ReqSpecImpl CONNECT ApiR where@@ -160,6 +164,8 @@   handler _ _ = respond () instance ApiHandler ReqSpecImpl DELETE ApiR where   handler _ _ = respond ()+instance ApiHandler ReqSpecImpl OPTIONS ApiR where+  handler _ _ = respond ["GET", "POST"]  formHeaders :: [(ByteString, ByteString)] -> [(ByteString, ByteString)] -> [Header] formHeaders headerKvs cookieKvs = map toHeader headerKvs <> [toCookie cookieKvs]@@ -194,7 +200,7 @@       request methodTrace "api" [] "" `shouldRespondWith` "[]" { matchStatus = 200 }   context "OPTIONS Request" $ do     it "should be 200 ok" $ do-      request methodOptions "api" [] "" `shouldRespondWith` "[]" { matchStatus = 200 }+      request methodOptions "api" [] "" `shouldRespondWith` "[\"GET\",\"POST\"]" { matchStatus = 200 }   context "CONNECT Request" $ do     it "should be 200 ok" $ do       request methodConnect "api" [] "" `shouldRespondWith` "[]" { matchStatus = 200 }
webapi.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                webapi-version:             0.1.0.0+version:             0.2.0.0 synopsis:            WAI based library for web api description:         WAI based library for web api          homepage:            http://byteally.github.io/webapi/@@ -78,9 +78,12 @@     cpp-options:       -DTEST     -- ghc-options:       -Wall      build-depends:     base              >=4.7 && <4.9+                     , aeson             >=0.8 && <0.9+                     , case-insensitive  == 1.2.*                      , wai               == 3.0.*                      , wai-extra         == 3.0.*                      , warp              == 3.1.*+                     , http-media        == 0.6.*                      , http-types        == 0.8.*                      , hspec             == 2.1.*                      , hspec-wai         == 0.6.*