Upgrade to Pro — share decks privately, control downloads, hide ads and more …

http4k - the Swiss Army Knife for Kotlin HTTP apps

http4k - the Swiss Army Knife for Kotlin HTTP apps

An overview of the state of the http4k libraries, given at the Google Developer Experts Kotlin Meetup.

David Denton

April 30, 2021
Tweet

More Decks by David Denton

Other Decks in Programming

Transcript

  1. HTTP4K
    the Swiss Army Knife for
    Kotlin HTTP apps

    View Slide

  2. THE WHAT AND THE WHY OF HTTP4K?
    ๏ Toolkit for building HTTP-based applications.
    ๏ Leverage Kotlin language features.
    ๏ Based on functional concepts: composition and immutability.
    ๏ No magic. No reflection. No annotations.
    ๏ Minimal/no dependencies.
    ๏ Supports Test-Driven approaches, easily testable outside container.

    View Slide

  3. THE CORE HTTP4K TYPES
    Type Signature(s) Usage
    HttpHandler (Request) -> Response { req: Request -> Response(OK).body(req.body) }
    Filter (HttpHandler) -> HttpHandler
    Filter { next ->
    { req -> next(req).removeHeader(“Date") }
    }
    Router (Request) -> RouterMatch
    Router {
    Unmatched(RouterDescription("no match"))
    }
    Lens
    Inject (TARGET) -> O
    Extract (O, TARGET) -> TARGET
    val lens = Query.int().required("age")
    val age: Int = lens(request)
    val reqWithAge = lens(21, Request(GET, ""))
    AppLoader (Map) -> HttpHandler
    AppLoader { env: Map ->
    { req -> Response(OK).body(env.toString()) }
    }

    View Slide

  4. THE “SERVER AS A FUNCTION” MODEL
    ๏ Based on uniform client/server model
    ๏ endpoints are HttpHandler functions
    ๏ modules are HttpHandler functions
    ๏ servers are HttpHandler functions
    ๏ clients are HttpHandler functions

    View Slide

  5. WHAT DOES THIS MEAN FOR HTTP4K?
    ๏ The SaaF model unlocks new powers
    ๏ For application design:
    ๏ lightweight, functional, no-magic services
    ๏ simple, extensible, composable abstractions
    ๏ apps become pure functions which can be easily tested
    ๏ For testing (which we are obsessive about!):
    ๏ servers and clients can be interchanged
    ๏ zero custom testing infrastructure
    ๏ tests are portable across the pyramid AND technology

    View Slide

  6. SOME STATS ABOUT THE PROJECT
    ๏ v1 released in May 2017
    ๏ 450 releases, 5.5k commits, 81 contributors
    ๏ 50 modules, supporting 17 server and serverless backends
    ๏ Core module is still only 1mb (zero dependencies)
    ๏ Usage seems to be pan-industry - lots of FS/banking
    ๏ More recently, uptick in serverless interest

    View Slide

  7. INTEGRATIONS SO FAR…
    HamKrest
    x

    View Slide

  8. WHAT’S NEXT?
    ๏ Push towards zero-config native binaries
    ๏ Serverless
    ๏ New DSL-driven FunctionHandler abstraction
    ๏ Super-lightweight AWS Lambda runtime
    ๏ http4k-connect: SaaF-friendly clients & fakes
    ๏ Tooling to push boundaries of multi-service testing

    View Slide

  9. THANKS!
    https://toolbox.http4k.org https://http4k.org http4k/connect
    @http4k
    #http4k@kotlinlang

    View Slide

  10. AND FINALLY - SOME WORDS FROM OUR AMAZING COMMUNITY…
    "I find the entire http4k project quite exemplary in both function and style/form. At first glance
    my impression was that it must be deficient because the code-base was too small and the
    style - simple and elegant -- to the point I was skeptical it would actually work in 'the real
    world'. I have verified to my satisfaction that I was totally wrong. The apparent simplicity is
    actually elegance -- a direct representative of the overall design architecture.
    So thank you -- not just for a great library but also an inspiration and example of excellent
    engineering we could all strive to follow as a model of something done well."
    - David A. Lee

    View Slide