Nothing Special   »   [go: up one dir, main page]

skip to main content
10.1145/2808098.2808099acmconferencesArticle/Chapter ViewAbstractPublication PagesicfpConference Proceedingsconference-collections
research-article

Type-level web APIs with Servant: an exercise in domain-specific generic programming

Published: 30 August 2015 Publication History

Abstract

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.

References

[1]
T. Altenkirch and C. McBride. Generic programming within dependently typed programming. In IFIP TC2/WG2.1 WGP, pages 1–20. Kluwer, 2003.
[2]
P. Bahr and T. Hvitved. Compositional data types. In WGP 2011, pages 83–94. ACM, 2011.
[3]
API Blueprint: Format 1A Revision 8. URL https://github. com/apiaryio/api-blueprint/blob/master/API%20Blueprint% 20Specification.md. Accessed: 2015-07-19. J. Carette, O. Kiselyov, and C.-c. Shan. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. Journal of Functional Programming, 19:509–543, Sept. 2009.
[4]
M. M. T. Chakravarty, G. C. Ditu, and R. Leshchinskiy. Instant generics: Fast and easy. Accessed: 2015-07-19. URL https://www.cse.unsw. edu.au/~chak/papers/CDL09.html. E. Christensen, F. Curbera, G. Meredith, and S. Weerawarana. Web Services Description Language ( WSDL ) 1.1, Mar. 2001. URL http://www.w3. org/TR/wsdl. Accessed: 2015-07-19. E. de Vries and A. Löh. True sums of products. In WGP 2014, pages 83–94. ACM, 2014.
[5]
C. Dornan and A. Gundry. api-tools. URL https://hackage.haskell. org/package/api-tools. Accessed: 2015-07-19. R. A. Eisenberg and S. Weirich. Dependently typed programming with singletons. In Haskell 2012, pages 117–130. ACM, 2012.
[6]
M. Fischmann and A. Löh. configifier, 2015. URL https://hackage. haskell.org/package/configifier. Accessed: 2015-07-19. N. Freed and N. Borenstein. Multipurpose internet mail extensions ( MIME ) part two: Media types, Nov. 1996. URL http://tools.ietf.org/ html/rfc2046. Happstack Team. happstack-server. URL https://hackage.haskell. org/package/happstack-server. Accessed: 2015-07-19. S. Holdermans, J. Jeuring, A. Löh, and A. Rodriguez. Generic views on data types. In MPC 2006, pages 209–234. Springer-Verlag, 2006.
[7]
R. Lämmel and K. Ostermann. Software extension and integration with type classes. In GPCE 2006, pages 161–170. ACM, 2006.
[8]
rest-core. URL https://hackage.haskell.org/package/rest-core. Accessed: 2015-07-19. J. C. Reynolds. User-defined types and procedural data structures as complementary approaches to data abstraction. In S. A. Schuman, editor, New Directions in Algorithmic Languages, pages 157–168. INRIA, 1975.
[9]
A. Rodriguez, J. Jeuring, P. Jansson, A. Gerdes, O. Kiselyov, and B. C. d. S. Oliveira. Comparing libraries for generic programming in Haskell. In Haskell 2008, pages 111–122. ACM, 2008.
[10]
servant – Webservice API combinators. URL https://haskell-servant. github.io. Accessed: 2015-07-19. M. Snoyman. Developing Web Applications with Haskell and Yesod. O’Reilly Media, Apr. 2012.
[11]
S. D. Swierstra and L. Duponcheel. Deterministic, error-correcting combinator parsers. In Advanced Functional Programming, volume 1129 of LNCS, pages 184–207. Springer-Verlag, 1996.
[12]
W. Swierstra. Data types à la carte. Journal of Functional Programming, 18(4):423–436, July 2008.
[13]
The RAML Workgroup. RAML ™ version 0.8: REST ful API modeling. URL http://raml.org/spec.html. Accessed: 2015-07-19. P. Wadler. The expression problem, Nov. 1998. URL http://homepages. inf.ed.ac.uk/wadler/papers/expression/expression.txt. Email to the java-genericity mailing list. B. A. Yorgey, S. Weirich, J. Cretin, S. Peyton Jones, D. Vytiniotis, and J. P. Magalhães. Giving Haskell a promotion. In TLDI 2012, pages 53–66. ACM, 2012.

Cited By

View all
  • (2024)Functional Reactive Programming, RearrangedProceedings of the 17th ACM SIGPLAN International Haskell Symposium10.1145/3677999.3678278(55-67)Online publication date: 29-Aug-2024
  • (2023)Typed Design Patterns for the Functional EraProceedings of the 1st ACM SIGPLAN International Workshop on Functional Software Architecture10.1145/3609025.3609477(40-48)Online publication date: 30-Aug-2023
  • (2023)HasChor: Functional Choreographic Programming for All (Functional Pearl)Proceedings of the ACM on Programming Languages10.1145/36078497:ICFP(541-565)Online publication date: 30-Aug-2023
  • Show More Cited By

Index Terms

  1. Type-level web APIs with Servant: an exercise in domain-specific generic programming

    Recommendations

    Comments

    Please enable JavaScript to view thecomments powered by Disqus.

    Information & Contributors

    Information

    Published In

    cover image ACM Conferences
    WGP 2015: Proceedings of the 11th ACM SIGPLAN Workshop on Generic Programming
    August 2015
    44 pages
    ISBN:9781450338103
    DOI:10.1145/2808098
    Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

    Sponsors

    Publisher

    Association for Computing Machinery

    New York, NY, United States

    Publication History

    Published: 30 August 2015

    Permissions

    Request permissions for this article.

    Check for updates

    Author Tags

    1. Haskell
    2. embedded domain-specific languages
    3. generic programming
    4. type-level programming
    5. web programming

    Qualifiers

    • Research-article

    Conference

    ICFP'15
    Sponsor:

    Acceptance Rates

    Overall Acceptance Rate 30 of 43 submissions, 70%

    Upcoming Conference

    ICFP '25
    ACM SIGPLAN International Conference on Functional Programming
    October 12 - 18, 2025
    Singapore , Singapore

    Contributors

    Other Metrics

    Bibliometrics & Citations

    Bibliometrics

    Article Metrics

    • Downloads (Last 12 months)28
    • Downloads (Last 6 weeks)5
    Reflects downloads up to 10 Nov 2024

    Other Metrics

    Citations

    Cited By

    View all
    • (2024)Functional Reactive Programming, RearrangedProceedings of the 17th ACM SIGPLAN International Haskell Symposium10.1145/3677999.3678278(55-67)Online publication date: 29-Aug-2024
    • (2023)Typed Design Patterns for the Functional EraProceedings of the 1st ACM SIGPLAN International Workshop on Functional Software Architecture10.1145/3609025.3609477(40-48)Online publication date: 30-Aug-2023
    • (2023)HasChor: Functional Choreographic Programming for All (Functional Pearl)Proceedings of the ACM on Programming Languages10.1145/36078497:ICFP(541-565)Online publication date: 30-Aug-2023
    • (2022)Verified Causal Broadcast with Liquid HaskellProceedings of the 34th Symposium on Implementation and Application of Functional Languages10.1145/3587216.3587222(1-13)Online publication date: 31-Aug-2022
    • (2021)Dynamic Editors for Well-Typed ExpressionsTrends in Functional Programming10.1007/978-3-030-83978-9_3(44-66)Online publication date: 23-Aug-2021
    • (2020)Describing microservices using modern Haskell (experience report)Proceedings of the 13th ACM SIGPLAN International Symposium on Haskell10.1145/3406088.3409018(1-8)Online publication date: 27-Aug-2020
    • (2019)Saint: An API-Generic Type-Safe InterpreterZivilgesellschaft und Wohlfahrtsstaat im Wandel10.1007/978-3-030-18506-0_5(94-113)Online publication date: 24-Apr-2019
    • (2018)Authenticated modular maps in HaskellProceedings of the 3rd ACM SIGPLAN International Workshop on Type-Driven Development10.1145/3240719.3241790(1-13)Online publication date: 27-Sep-2018

    View Options

    Get Access

    Login options

    View options

    PDF

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader

    Media

    Figures

    Other

    Tables

    Share

    Share

    Share this Publication link

    Share on social media