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

[ bsd3, library, web ] [ Propose Tags ]

Surjective single page application routing with Servant. Surjectivity 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]
Versions [faq] 0.1.0.0, 0.1.0.1
Change log CHANGELOG.md
Dependencies aeson (>=1.4.4 && <1.5), base (>=4.12.0 && <4.15), bytestring (>=0.10.8 && <0.11), 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), jsaddle (>=0.9.7 && <0.20), jsaddle-dom (>=0.9.3 && <0.20), lens (>=4.17.1 && <5.0), network-uri (>=2.6.1 && <2.8), servant (>=0.16 && <0.18), servant-client (>=0.16.0 && <0.18), servant-client-ghcjs, 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
Maintainer fresheyeball@protonmail.com
Category Web
Source repo head: git clone https://gitlab.com/fresheyeball/Shpadoinkle.git
Uploaded by fresheyeball at 2020-05-10T20:36:56Z
Distributions NixOS:0.1.0.1
Downloads 61 total (61 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for Shpadoinkle-router-0.1.0.1

[back to package description]

Shpadoinkle Servant Router

Goldwater 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:

  • Type alias for the recognized URIs
  • ADT representing views that can be rendered

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.

Since 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
routes
  =    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.