servant-named: Add named endpoints to servant

[ bsd3, library, web ] [ Propose Tags ]

Please see

[Skip to Readme]




Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS]
Dependencies base (>=4.9 && <5), servant (>=0.7.1 && <1) [details]
License BSD-3-Clause
Copyright 2017 Ben Weitzman
Author Ben Weitzman
Revised Revision 2 made by benweitzman at 2017-02-01T18:12:07Z
Category Web
Home page
Source repo head: git clone
Uploaded by benweitzman at 2017-02-01T18:09:21Z
Distributions NixOS:
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1148 total (5 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-02-01 [all 1 reports]

Readme for servant-named-

[back to package description]


This package aims to address an issue with the amazing servant library, wherein it can be hard to manage two complex lists of API endpoints (one of types, and one of handlers), making sure to keep them in the same order.

To address this, we introduce the concept of named endpoints. When using named endpoints, it's no longer necessary to keep endpoint types and handlers in the same order. When serving the servant application, the types and handlers are automatically matched up according to their names. Here's a little example:

handler :: Server API
handler = fromNamed $ Named @"getUser"  := return
                ::<|> Named @"getUsers" := return [1,2,3]
                ::<|> Nil

type API = FromNamed ( Named "getUsers" := "user" :> Get '[JSON] [Int]
                 ::<|> Named "getUser"  := "user" :> Capture "id" Int :> Get '[JSON] Int
                 ::<|> Nil

The endpoints are defined in opposite orders, but this still typechecks and works as expected!