The servant-named package

[Tags:bsd3, library, test]

Please see README.md


[Skip to Readme]

Properties

Versions 0.1.0.0
Dependencies base (>=4.9 && <5), servant (>=0.7.1 && <1) [details]
License BSD3
Copyright 2017 Ben Weitzman
Author Ben Weitzman
Maintainer benweitzman@gmail.com
Category Web
Home page https://github.com/bemweitzman/servant-named#readme
Source repository head: git clone https://github.com/benweitzman/servant-named
Uploaded Wed Feb 1 18:09:21 UTC 2017 by benweitzman
Updated Wed Feb 1 18:12:07 UTC 2017 by benweitzman to revision 2
Distributions NixOS:0.1.0.0
Downloads 44 total (11 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-02-01 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for servant-named

Readme for servant-named-0.1.0.0

servant-named

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!