on 950e322 help sign in
.gitignore−2
since splitsnapshots
unifiedsplit
@@ -7,5 +7,3 @@ 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](https://haskell-servant.readthedocs.io) combinators, you can use
10+[servant](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 = "1aba6f367982bd6dd78ec2fda75ab246a62d32c5" ;
2+ rev = "df0bdcca5eb2a3236ec0496e4430d91876b29cf5";
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 = "137vg6i8yy4lp6rz4wbvvhfcc9d9qf7j1b3fnng3r7sj63k7j664" ;
6+ sha256 = "1ja3vkq9px8f9iyiazq44mamaahgiphi9l236pvzbl5jvhi5c4qr";
7 }) {}
7 }) {}
src/Servant/Reflex.hs+16−31
@@ -39,36 +39,34 @@ 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
42import qualified Data.CaseInsensitive as CI
45import qualified Data.CaseInsensitive as CI
43import Data.Functor.Identity
46import Data.Functor.Identity
44−import qualified Data.Map as Map
45−import Data.Monoid ((<>))
46import Data.Proxy (Proxy (..))
47import Data.Proxy (Proxy (..))
47−import qualified Data.Set as Set
48+import qualified Data.Map as Map
48import Data.Text (Text)
49import Data.Text (Text)
49import qualified Data.Text as T
50import 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, Header, Headers (..),
55+ Capture, contentType, Header,
56− HttpVersion, IsSecure,
56+ Headers(..), 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)
64import qualified Servant.Auth as Auth
62import qualified Servant.Auth as Auth
65
63
66import Reflex.Dom.Core (Dynamic, Event, Reflex,
64import Reflex.Dom.Core (Dynamic, Event, Reflex,
67− XhrRequest (..), XhrResponse (..),
65+ XhrRequest(..),
68− XhrResponseHeaders (..),
66+ XhrResponseHeaders(..),
69− attachPromptlyDynWith, constDyn, ffor,
67+ XhrResponse(..), attachPromptlyDynWith, constDyn, ffor, fmapMaybe,
70− fmapMaybe, leftmost,
71− performRequestsAsync)
68+ leftmost, performRequestsAsync,
69+ )
72------------------------------------------------------------------------------
70------------------------------------------------------------------------------
73import Servant.Common.BaseUrl (BaseUrl(..), Scheme(..), baseUrlWidget,
71import Servant.Common.BaseUrl (BaseUrl(..), Scheme(..), baseUrlWidget,
74 showBaseUrl,
72 showBaseUrl,
@@ -329,19 +327,6 @@ instance HasClient t m sublayout tag
329 clientWithRouteAndResultHandler Proxy =
327 clientWithRouteAndResultHandler Proxy =
330 clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
328 clientWithRouteAndResultHandler (Proxy :: Proxy sublayout)
331
329
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−
345
330
346-- | If you use a 'QueryParam' in one of your endpoints in your API,
331-- | If you use a 'QueryParam' in one of your endpoints in your API,
347-- the corresponding querying function will automatically take
332-- the corresponding querying function will automatically take
src/Servant/Reflex/Multi.hs+22−35
@@ -37,30 +37,28 @@ 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,
51+ HttpVersion, IsSecure, MimeRender (..),
52− MimeRender (..), MimeUnrender,
53− NoContent, QueryFlag, QueryParam,
52+ MimeUnrender, NoContent, QueryFlag,
54− QueryParams, Raw, ReflectMethod (..),
53+ QueryParam, QueryParams, Raw,
55− RemoteHost, ReqBody,
54+ ReflectMethod (..), RemoteHost,
56− ToHttpApiData (..), Vault, Verb,
55+ ReqBody, ToHttpApiData (..), Vault,
57− contentType)
56+ Verb, contentType)
58−import Servant.API.Description (Summary)
57+
59−
60−import Reflex.Dom.Core (Dynamic, Event, Reflex,
58+import Reflex.Dom.Core (Dynamic, Event, Reflex,
61− XhrRequest (..),
59+ XhrRequest (..),
62− XhrResponseHeaders (..),
60+ XhrResponseHeaders (..),
63− attachPromptlyDynWith, constDyn)
61+ attachPromptlyDynWith, constDyn)
64------------------------------------------------------------------------------
62------------------------------------------------------------------------------
65import Servant.Common.BaseUrl (BaseUrl (..), Scheme (..),
63import Servant.Common.BaseUrl (BaseUrl (..), Scheme (..),
66 SupportsServantReflex)
64 SupportsServantReflex)
@@ -242,17 +240,6 @@ instance HasClientMulti t m sublayout f tag
242 clientWithRouteMulti (Proxy :: Proxy sublayout) q f tag
240 clientWithRouteMulti (Proxy :: Proxy sublayout) q f tag
243
241
244
242
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−
256------------------------------------------------------------------------------
243------------------------------------------------------------------------------
257instance (KnownSymbol sym,
244instance (KnownSymbol sym,
258 ToHttpApiData a,
245 ToHttpApiData a,