on master help sign in
.gitignore+2
since splitsnapshots
unifiedsplit
@@ -7,3 +7,5 @@ log
7*.stats
7*.stats
8out
8out
9/.stack-work/
9/.stack-work/
10+TAGS
11+dist-newstyle
README.md+1−1
@@ -7,7 +7,7 @@
7Keeping your frontend in sync with your API server can be difficult - when the
7Keeping your frontend in sync with your API server can be difficult - when the
8API changes its input parameters or return type, XHR requests from the
8API changes its input parameters or return type, XHR requests from the
9frontend will fail at runtime. If your API is defined by
9frontend will fail at runtime. If your API is defined by
10−[servant](haskell-servant.readthedocs.io) combinators, you can use
10+[servant](https://haskell-servant.readthedocs.io) combinators, you can use
11`servant-reflex` to share the API between the server and frontend.
11`servant-reflex` to share the API between the server and frontend.
12Syncronization between is checked at compile time, and rather than building XHR
12Syncronization between is checked at compile time, and rather than building XHR
13requests by hand, API endpoints are available behind `reflex`'s FRP semantics.
13requests by hand, API endpoints are available behind `reflex`'s FRP semantics.
nix/reflex-platform.nix+2−2
@@ -1,7 +1,7 @@
1let
1let
2− rev = "df0bdcca5eb2a3236ec0496e4430d91876b29cf5";
2+ rev = "1aba6f367982bd6dd78ec2fda75ab246a62d32c5" ;
3in import (builtins.fetchTarball
3in import (builtins.fetchTarball
4 {
4 {
5 url = "https://github.com/reflex-frp/reflex-platform/archive/${rev}.tar.gz";
5 url = "https://github.com/reflex-frp/reflex-platform/archive/${rev}.tar.gz";
6− sha256 = "1ja3vkq9px8f9iyiazq44mamaahgiphi9l236pvzbl5jvhi5c4qr";
6+ sha256 = "137vg6i8yy4lp6rz4wbvvhfcc9d9qf7j1b3fnng3r7sj63k7j664" ;
7 }) {}
7 }) {}
src/Servant/Reflex.hs+31−16
@@ -39,34 +39,36 @@ module Servant.Reflex
39
39
40------------------------------------------------------------------------------
40------------------------------------------------------------------------------
41import Control.Applicative
41import Control.Applicative
42−import Data.Monoid ((<>))
43−import qualified Data.Set as Set
44−import qualified Data.Text.Encoding as E
45import qualified Data.CaseInsensitive as CI
42import qualified Data.CaseInsensitive as CI
46import Data.Functor.Identity
43import Data.Functor.Identity
47−import Data.Proxy (Proxy (..))
48import qualified Data.Map as Map
44import qualified Data.Map as Map
45+import Data.Monoid ((<>))
46+import Data.Proxy (Proxy (..))
47+import qualified Data.Set as Set
49import Data.Text (Text)
48import Data.Text (Text)
50import qualified Data.Text as T
49import qualified Data.Text as T
50+import qualified Data.Text.Encoding as E
51import GHC.Exts (Constraint)
51import GHC.Exts (Constraint)
52import GHC.TypeLits (KnownSymbol, symbolVal)
52import GHC.TypeLits (KnownSymbol, symbolVal)
53−import Servant.API ((:<|>)(..),(:>), BasicAuth,
53+import Servant.API ((:<|>) (..), (:>), BasicAuth,
54− BasicAuthData, BuildHeadersTo(..),
54+ BasicAuthData, BuildHeadersTo (..),
55− Capture, contentType, Header,
55+ Capture, Header, Headers (..),
56− Headers(..), HttpVersion, IsSecure,
56+ HttpVersion, IsSecure,
57− MimeRender(..), MimeUnrender,
57+ MimeRender (..), MimeUnrender,
58 NoContent, QueryFlag, QueryParam,
58 NoContent, QueryFlag, QueryParam,
59− QueryParams, Raw, ReflectMethod(..),
59+ QueryParams, Raw, ReflectMethod (..),
60 RemoteHost, ReqBody,
60 RemoteHost, ReqBody,
61− ToHttpApiData(..), Vault, Verb)
61+ ToHttpApiData (..), Vault, Verb,
62+ contentType)
63+import Servant.API.Description (Summary)
62import qualified Servant.Auth as Auth
64import qualified Servant.Auth as Auth
63
65
64import Reflex.Dom.Core (Dynamic, Event, Reflex,
66import Reflex.Dom.Core (Dynamic, Event, Reflex,
65− XhrRequest(..),
67+ XhrRequest (..), XhrResponse (..),
66− XhrResponseHeaders(..),
68+ XhrResponseHeaders (..),
67− XhrResponse(..), attachPromptlyDynWith, constDyn, ffor, fmapMaybe,
69+ attachPromptlyDynWith, constDyn, ffor,
70+ fmapMaybe, leftmost,
68− leftmost, performRequestsAsync,
71+ performRequestsAsync)
69− )
70------------------------------------------------------------------------------
72------------------------------------------------------------------------------
71import Servant.Common.BaseUrl (BaseUrl(..), Scheme(..), baseUrlWidget,
73import Servant.Common.BaseUrl (BaseUrl(..), Scheme(..), baseUrlWidget,
72 showBaseUrl,
74 showBaseUrl,
@@ -327,6 +329,19 @@ instance HasClient t m sublayout tag
327 clientWithRouteAndResultHandler Proxy =
329 clientWithRouteAndResultHandler Proxy =
328 clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
330 clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
329
331
332+-- | Using a 'Summary' combinator in your API doesn't affect the client
333+-- functions.
334+instance (HasClient t m sublayout tag, KnownSymbol sym)
335+ => HasClient t m (Summary sym :> sublayout) tag where
336+
337+ type Client t m (Summary sym :> sublayout) tag =
338+ Client t m sublayout tag
339+
340+ clientWithRouteAndResultHandler Proxy =
341+ clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
342+
343+
344+
330
345
331-- | If you use a 'QueryParam' in one of your endpoints in your API,
346-- | If you use a 'QueryParam' in one of your endpoints in your API,
332-- the corresponding querying function will automatically take
347-- the corresponding querying function will automatically take
src/Servant/Reflex/Multi.hs+35−22
@@ -37,28 +37,30 @@ module Servant.Reflex.Multi (
37 ) where
37 ) where
38
38
39------------------------------------------------------------------------------
39------------------------------------------------------------------------------
40−import Control.Applicative (liftA2)
40+import Control.Applicative (liftA2)
41−import Data.Functor.Compose (Compose (..), getCompose)
41+import Data.Functor.Compose (Compose (..), getCompose)
42−import Data.Proxy (Proxy (..))
42+import Data.Proxy (Proxy (..))
43−import qualified Data.Set as Set
43+import qualified Data.Set as Set
44−import Data.Text (Text)
44+import Data.Text (Text)
45−import qualified Data.Text as T
45+import qualified Data.Text as T
46−import qualified Data.Text.Encoding as E
46+import qualified Data.Text.Encoding as E
47−import GHC.TypeLits (KnownSymbol, symbolVal)
47+import GHC.TypeLits (KnownSymbol, symbolVal)
48−import Servant.API ((:<|>) (..), (:>), BasicAuth,
48+import Servant.API ((:<|>) (..), (:>), BasicAuth,
49− BasicAuthData, BuildHeadersTo (..),
49+ BasicAuthData, BuildHeadersTo (..),
50− Capture, Header, Headers (..),
50+ Capture, Header, Headers (..),
51− HttpVersion, IsSecure, MimeRender (..),
51+ HttpVersion, IsSecure,
52+ MimeRender (..), MimeUnrender,
52− MimeUnrender, NoContent, QueryFlag,
53+ NoContent, QueryFlag, QueryParam,
53− QueryParam, QueryParams, Raw,
54+ QueryParams, Raw, ReflectMethod (..),
54− ReflectMethod (..), RemoteHost,
55+ RemoteHost, ReqBody,
55− ReqBody, ToHttpApiData (..), Vault,
56+ ToHttpApiData (..), Vault, Verb,
56− Verb, contentType)
57+ contentType)
57−
58+import Servant.API.Description (Summary)
59+
58−import Reflex.Dom.Core (Dynamic, Event, Reflex,
60+import Reflex.Dom.Core (Dynamic, Event, Reflex,
59− XhrRequest (..),
61+ XhrRequest (..),
60− XhrResponseHeaders (..),
62+ XhrResponseHeaders (..),
61− attachPromptlyDynWith, constDyn)
63+ attachPromptlyDynWith, constDyn)
62------------------------------------------------------------------------------
64------------------------------------------------------------------------------
63import Servant.Common.BaseUrl (BaseUrl (..), Scheme (..),
65import Servant.Common.BaseUrl (BaseUrl (..), Scheme (..),
64 SupportsServantReflex)
66 SupportsServantReflex)
@@ -240,6 +242,17 @@ instance HasClientMulti t m sublayout f tag
240 clientWithRouteMulti (Proxy :: Proxy sublayout) q f tag
242 clientWithRouteMulti (Proxy :: Proxy sublayout) q f tag
241
243
242
244
245+------------------------------------------------------------------------------
246+instance (HasClientMulti t m sublayout f tag, KnownSymbol sym)
247+ => HasClientMulti t m (Summary sym :> sublayout) f tag where
248+
249+ type ClientMulti t m (Summary sym :> sublayout) f tag =
250+ ClientMulti t m sublayout f tag
251+
252+ clientWithRouteMulti Proxy q f tag =
253+ clientWithRouteMulti (Proxy :: Proxy sublayout) q f tag
254+
255+
243------------------------------------------------------------------------------
256------------------------------------------------------------------------------
244instance (KnownSymbol sym,
257instance (KnownSymbol sym,
245 ToHttpApiData a,
258 ToHttpApiData a,