Type-level Web APIs with Servant – An exercise in domain-specific generic programming
Alp Mestanogullari, Sönke Hahn, Julian K. Arni, Andres Löh

We describe the design and motivation for Servant, an extensible, type-level DSL for describing Web APIs. Servant APIs are Haskell types. An API type can be interpreted in several different ways: as a server that processes requests, interprets them and dispatches them to appropriate handlers; as a client that can correctly query the endpoints of the API; as systematic documentation for the API; and more. Servant is fully extensible: the API language can be augmented with new constructs, and new interpretations can be defined. The key Haskell features making all this possible are data kinds, (open) type families and (open) type classes. The techniques we use are reminiscent of general-purpose generic programming. However, where most generic programming libraries are interested in automatically deriving programs for a large class of datatypes from many different domains, we are only interested in a small class of datatypes that is used in the DSL for describing APIs.

Download / Links
Talk, presented at WGP 2015
Servant project homepage

Valid XHTML 1.0! Valid CSS!

Andres Löh, 2016-02-04