Shpadoinkle-router: A single page application rounter for Shpadoinkle based on Servant.

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Surjective single page application routing with Servant. Surjectivity in this context means routes can be backward compatible, allowing URLs to evolve. Since routes are specified as Servant combinators, serving these routes from the backend is trivial. For an example of leveraging the client-server isomorphism via Servant specification, check the servant-crud example.

[Skip to Readme]


Change log
Dependencies aeson (>=1.4.4 && <1.6), base (>=4.12.0 && <4.16), bytestring (>=0.10.8 && <0.12), compactable (>=0.1.2 && <0.2), exceptions (>=0.10.3 && <0.11), ghcjs-dom (>=0.9.4 && <0.20), http-api-data (>=0.4.1 && <0.5), http-media, jsaddle (>=0.9.7 && <0.20), lens (>=4.17.1 && <5.0), network-uri (>=2.6.1 && <2.8), servant (>=0.16 && <0.19), servant-client (>=0.16.0 && <0.18), servant-client-js (>=0.1 && <0.2), servant-server (>=0.16 && <0.18), Shpadoinkle, Shpadoinkle-backend-static, text (>=1.2.3 && <1.3), unliftio (>=0.2.12 && <0.3), wai (>=3.2.2 && <3.3), wai-app-static (>=3.1.6 && <3.2), warp (>=3.2.28 && <3.3) [details]
License BSD-3-Clause
Author Isaac Shapira
Category Web
Source repo head: git clone
Uploaded by fresheyeball at 2020-10-07T16:13:41Z


[Index] [Quick Jump]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Readme for Shpadoinkle-router-

[back to package description]

Shpadoinkle Servant Router

Goldwater Haddock BSD-3 built with nix Hackage Hackage Deps Hackage CI

A Servant combinator-based router for Shpadoinkle single-page applications. Consuming this router requires that you provide two types:

The relationship between these two types is surjective. meaning more than one URI may result in the same route. This is important for backward compatibility, so the routing schema can evolve while still supporting older schemas.

Because interactions are done through the ADT, application code should be type-safe, and route canonically.

-- The accepted URIs
type SPA
  =            "echo" :> QueryParam "echo" Text :> Raw
  :<|> "v2" :> "echo" :> QueryParam "echo" Text :> Raw
  :<|> "home" :> Raw

-- The routes that can be rendered
data Route
  = Echo (Maybe Text)
  | Home

-- Surjection from URIs to routes
routes :: SPA :>> Route
  =    REcho
  :<|> REcho
  :<|> Home

-- Canonical URI for each route
instance Routed SPA Route where
  redirect = \case
    REcho t -> Redirect (Proxy @("v2" :> "echo" :> QueryParam "echo" Text :> Raw)) ($ t)
    Home    -> Redirect (Proxy @("home" :> Raw)) id

The above specification can be used on both the client and the server. See the servant-crud example for more on how to use this technique.