Skip to content

Finch 0.11-M4

Compare
Choose a tag to compare
@vkostyukov vkostyukov released this 17 Oct 03:57
· 1190 commits to master since this release
  • Endpoints testing now easier with polymorphic withBody (see #646)
  • Simplifying the behavior around empty entries (see #642)
  • Better error messages in finch-circe (see #648)

Polymorphic Input.withBody

It's now possible to utilize content-types (type-level strings) in Input.withBody such that a proper encoder (i.e., io.finch.Encode) is picked for the arbitrary value.

Before:

Input.post("/").withBody(Buf.Utf8("text"), Some("text/plain;charset=utf8"))
Input.post("/").withJson(Map("a" -> "b"), Some(Charsets.Utf8))

Now:

// Now:
Input.post("/").withBody[Text.Plain]("text", Some(Charsets.Utf8))
Input.post("/").withBody[Application.Json](Map("a" -> "b"), Some(Charsets.Utf8))

// We get the following for free:
import cats.instances.int._
Input.post("/").withBody[Text.Plain](42)

Empty strings are now treated as Some(""), not None

For the sake of principle of least astonishment, we decided to simplify Finch's core endpoints such as header, param, and body so they resolve into Some("") if the given entity is represented as an empty string (None before). This makes these endpoints both more flexible and less powerful (and actually more lightweight).