github finagle/finch 0.17.0
Finch 0.17

latest releases: v0.34.1, v0.34.0, v0.33.0...
6 years ago

This release features Finagle 18.2 and the brand new support to server-driven content negotiation.

Content Negotiation

An idea of supporting a content negotiation initially came up about two years ago, and it's finally become a reality (thanks to @imliar's inspiring contribution!). As of 0.17, it's possible to specify the list of supported content-types per endpoint and have the appropriate encoders be resolved at compile time. An actual encoder is dispatched later, at runtime, when client's Accept header value is known.

Content negotiation is disabled by default (for now). Use Bootstrap.configure to enable it:

import io.finch._

val s = Bootstrap.configure(negotiateContentType = true)
  .serve[Application.Json :+: Text.Plain :+: CNil](Endpoint.lift("Hello, World!"))
  .toService

In the example above, the "Hello, World!" endpoint may be served within both JSON and plain text payloads, depending on the Accept header value sent by a client. If nothing is provided, it defaults to the first content-type in the list (actually, a coproduct). Note: this program won't compile until both encoders are resolved.

Explicit Syntax (verb matching)

We tried to make the transition from implicit to explicit syntax as smooth as possible but it caused some non-trivial shadowing issues in the 0.16 release. Based on that, we made an executive decision to break an API (a little) and stop supplying a default syntax API in the io.finch._ import. Enable verb-matching syntax explicitly by importing io.finch.syntax._.

Don't miss a new finch release

NewReleases is sending notifications on new releases.