github zio/zio-http v3.1.0

one day ago

Highlights

Endpoint API

Codec Changes

Header and Query codecs are now Schema based. We added methods on QueryParams and Headers that set and get values based on Schema. This also enables to use case classes to get/set header/query values that are simple wrappers or have multiple primitive/collection fields. Docs have been added for more details.

case class Foo(a: Int, b: SimpleWrapper, c: NonEmptyChunk[String], chunk: Chunk[String])
val headersFoo   = Headers("a" -> "1", "b" -> "foo", "c" -> "2", "chunk" -> "foo", "chunk" -> "bar")
val foo = headersFoo.header[Foo]

Scala 3 Union Type support

Here an example

val unionWithErrorEndpoint
    : Endpoint[Unit, Unit, NotFound[EntityId] | String, UUID | Unit, AuthType.None] =
  Endpoint(Method.GET / "api" / "union-with-error")
    .out[UUID]
    .orOut[Unit](Status.NoContent)
    .outError[NotFound[EntityId]](Status.NotFound)
    .orOutError[String](Status.BadRequest)

For more details, please check the added documentation.

Performance improvements

We merged multiple PRs for improving routes look up time.
Also zio-schema and zio-json get huge performance boosts in recent versions, thanks to @plokhotnyuk and the versions have been updated in zio-http
Here is some before after comparison

One Scope per request handling

Before you could require a scope in a request handler and bubble this up to the apps default Scope. Since after an HTTP request its resources should be cleaned and not at the end of the Server app, this was a possible source for bugs.
Now, if a handler/route/routes needs a scope, you have to provide one. Adding a route to the server that requires a scope will lead to a compile error.
You can either use Handler.scoped or ZIO.scoped to provide a scope where needed.

Changes

🐛 Bug Fixes

  • CI: Fix scala_steward && Add dependabot to maintain GHA workflows @guizmaii (#3298)

🧰 Maintenance

Don't miss a new zio-http release

NewReleases is sending notifications on new releases.