@hackage / servant-match

Standalone implementation of servant’s dispatching mechanism

Latest0.1.1

About

Metadata

  • Last updated , by cocreature
  • License BSD-3-Clause
  • Categories Web Development
  • Maintained by: moritz.kiefer@purelyfunctional.org

  • Lottery factor: 0

Links

Installation

Tested Compilers

  1. 8.2.2
  2. 8.0.2
  3. 7.10.3

Readme

servant-match

Travis Hackage

This package provides a standalone implementation of dispatching a function by matching it against a Servant API. A common usecase for this is to convert an URI to an ADT that provides a more structured representation of the URL.

Usage

data DataView
  = Show
  | Edit
  deriving (Show, Eq)

data View
  = ViewUsers
  | ViewNewUser
  | ViewUser !Text !DataView
  deriving (Show, Eq)

data User = User

type API =
  "users" :> (Get '[JSON] [User] :<|> "new" :> ReqBody '[JSON] User :> Post '[JSON] User) :<|>
  "user" :> Capture "user" Text :>
    (Get '[JSON] User :<|>
     "edit" :> ReqBody '[JSON] User :> Put '[JSON] User)

parser :: MatchT API View
parser =
  (ViewUsers :<|> ViewNewUser) :<|> (\u -> ViewUser u Show :<|> ViewUser u Edit)