Skip to content

Releases: zio/zio-http

v1.0.0.0-RC24

09 Feb 10:08
4b760b4
Compare
Choose a tag to compare

Highlights

  • Websocket Client Support

      val url = "ws://localhost:8090/subscriptions"
      val app = Socket
        .collect[WebSocketFrame] {
          case WebSocketFrame.Text("BAZ") => ZStream.succeed(WebSocketFrame.close(1000))
          case frame                      => ZStream.succeed(frame)
        }
        .toSocketApp
        .connect(url) // creates a socket connection on the provided URL

💥 Breaking Changes

  • Drop toZIO and wrapZIO APIs

    private val app =
        Http.collectZIO[Request] {
          case Method.GET -> !! / "greet" / name  => UIO(Response.text(s"Greetings ${name}!"))
        }
  • Rename asString to encode in Scheme

    sealed trait Scheme { self =>
      def encode: String = Scheme.asString(self)
    }
  • Rename getHeaders to headers in ClientRequest

    final case class ClientRequest(
        method: Method,
        url: URL,
        headers: Headers = Headers.empty,
        data: HttpData = HttpData.empty,
        private val channelContext: ChannelHandlerContext = null,
      )
  • Remove get prefix from Public APIs

    Previous Current
    getBodyAsByteBuf bodyAsByteBuf
    getBodyAsString bodyAsString
    getBody body
    getHeaders headers
    getStatus status
    getStatus status
  • Rename asString to encode in URL

    def encode: String = ...
  • silent is removed from Http and HttpApp

Changes

🚀 Features

🐛 Bug Fixes

🧰 Maintenance

New Contributors

Full Changelog: v1.0.0.0-RC23...v1.0.0.0-RC24

v1.0.0.0-RC23

26 Jan 12:46
6850897
Compare
Choose a tag to compare

Highlights

  • Support middlewares on Http
  val middlewares: HttpMiddleware[Console with Clock, IOException] =
    // print debug info about request and response
    Middleware.debug ++
      // close connection if request takes more than 3 seconds
      Middleware.timeout(3 seconds) ++
      // add static header
      Middleware.addHeader("X-Environment", "Dev")

💥 Breaking Changes

  • Rename ClientParams to ClientRequest
  final case class ClientRequest(
    method: Method,
    url: URL,
    getHeaders: Headers = Headers.empty,
    data: HttpData = HttpData.empty,
    private val channelContext: ChannelHandlerContext = null,
  ) extends HeaderExtension[ClientRequest]
  • Constructor names updated as per ZIO 2
def fromZIO[R, E, A](z: ZIO[R, E, A]): HExit[R, E, A] = Effect(z.mapError(Option(_)))
def toZIO: ZIO[R, Option[E], A] = self match {
    case HExit.Success(a)  => ZIO.succeed(a)
    case HExit.Failure(e)  => ZIO.fail(Option(e))
    case HExit.Empty       => ZIO.fail(None)
    case HExit.Effect(zio) => zio
}

Changes

🚀 Features

🐛 Bug Fixes

🧰 Maintenance

New Contributors

Full Changelog: v1.0.0.0-RC22...v1.0.0.0-RC23

v2.0.0-RC2 - ZIO 2 Support

20 Jan 11:23
49a4e52
Compare
Choose a tag to compare

Changes

🚀 Features

Improvements

🐛 Bug Fixes

🧰 Maintenance

Full Changelog: v2.0.0-RC1...v2.0.0-RC2

v2.0.0-RC1 - ZIO 2 Support

13 Jan 15:38
33c7264
Compare
Choose a tag to compare

This release supports ZIO 2.0.0-RC1.

Note: For some time, releases targeting ZIO 1 will be using the version 1.0.0.0-RCx, whereas releases targeting ZIO 2 will be using the version 2.0.0-RCx

Highlights

💥 Breaking Changes

  • Follow ZIO 2.0 naming conventions Example: CollectM => CollectZIO
private val app = Http.collectZIO[Request] {
  case Method.GET -> !! / "random" => random.nextString(10).map(Response.text(_))
  case Method.GET -> !! / "utc"    => clock.currentDateTime.map(s => Response.text(s.toString))
}
  • Removed Type Params from Response
  • Removed Type Params from SocketApp
  • Removed Type Params from HttpData
  • Renamed socket to fromSocket in Response
  • Removed @@ composition from cookie
    private val app = Http.collect[Request] {
        case Method.GET -> !! / "cookie" =>
          Response.ok.addCookie(cookie.withPath(!! / "cookie").withHttpOnly)
    }
  • Builder pattern for SocketApp
    private val fooBar = Socket.collect[WebSocketFrame] {
        case WebSocketFrame.Text("FOO") => ZStream.succeed(WebSocketFrame.text("BAR"))
      }
    
    private val socketApp = {
        SocketApp(fooBar) // Called after each message being received on the channel
          // Called after the request is successfully upgraded to websocket
          .onOpen(open)
          // Called after the connection is closed
          .onClose(_ => console.putStrLn("Closed!").ignore)
      }

✨ New APIs

  • Added wrapZIO operator on Response
    private val app =
        Http.collectZIO[Request] {
          case Method.GET -> !! / "greet" / name  => Response.text(s"Greetings ${name}!").wrapZIO
        }
  • Added toSocketApp and toResponse on Socket
      private val app =
        Http.collectZIO[Request] {
          case Method.GET -> !! / "subscriptions" => socketApp.toResponse
        }
      
  • Added collectHttp on Http
    val app = Http.collectHttp[Request] {
    // Read the file as ZStream
    // Uses the blocking version of ZStream.fromFile
    case Method.GET -> !! / "blocking" => Http.fromStream(ZStream.fromFile(Paths.get("README.md")))
    }
  • Added provide on SocketApp

Changes

🚀 Features

Improvements

🐛 Bug Fixes

🧰 Maintenance

Thanks to @adamfraser, @kitlangton and @jdegoes for the work on ZIO 2 support!

New Contributors

Full Changelog: v1.0.0.0-RC21...v2.0.0-RC1

v1.0.0.0-RC22

12 Jan 13:38
2f0eb65
Compare
Choose a tag to compare

Highlights

💥 Breaking Changes

  • Follow ZIO 2.0 naming conventions Example: CollectM => CollectZIO
private val app = Http.collectZIO[Request] {
  case Method.GET -> !! / "random" => random.nextString(10).map(Response.text(_))
  case Method.GET -> !! / "utc"    => clock.currentDateTime.map(s => Response.text(s.toString))
}
  • Removed Type Params from Response
  • Removed Type Params from SocketApp
  • Removed Type Params from HttpData
  • Renamed socket to fromSocket in Response
  • Removed @@ composition from cookie
    private val app = Http.collect[Request] {
        case Method.GET -> !! / "cookie" =>
          Response.ok.addCookie(cookie.withPath(!! / "cookie").withHttpOnly)
    }
  • Builder pattern for SocketApp
    private val fooBar = Socket.collect[WebSocketFrame] {
        case WebSocketFrame.Text("FOO") => ZStream.succeed(WebSocketFrame.text("BAR"))
      }
    
    private val socketApp = {
        SocketApp(fooBar) // Called after each message being received on the channel
          // Called after the request is successfully upgraded to websocket
          .onOpen(open)
          // Called after the connection is closed
          .onClose(_ => console.putStrLn("Closed!").ignore)
      }

✨ New APIs

  • Added wrapZIO operator on Response
    private val app =
        Http.collectZIO[Request] {
          case Method.GET -> !! / "greet" / name  => Response.text(s"Greetings ${name}!").wrapZIO
        }
  • Added toSocketApp and toResponse on Socket
      private val app =
        Http.collectZIO[Request] {
          case Method.GET -> !! / "subscriptions" => socketApp.toResponse
        }
      
  • Added collectHttp on Http
    val app = Http.collectHttp[Request] {
    // Read the file as ZStream
    // Uses the blocking version of ZStream.fromFile
    case Method.GET -> !! / "blocking" => Http.fromStream(ZStream.fromFile(Paths.get("README.md")))
    }
  • Added provide on SocketApp
    private val echo = Socket.collect[WebSocketFrame] { case WebSocketFrame.Text(text) =>
    ZStream.repeat(WebSocketFrame.text(s"Received: $text")).schedule(Schedule.spaced(1 second)).take(3)
    }
    val env = Has.apply(Clock.Service.live)
    private val socketApp: SocketApp[Any] = SocketApp(echo).provide(env)

Changes

🚀 Features

Improvements

🐛 Bug Fixes

🧰 Maintenance

v1.0.0.0-RC21

30 Dec 05:06
1918118
Compare
Choose a tag to compare

Changes

✨ Features

🚀 Improvements

🐛 Bug Fixes

🧰 Maintenance

📓 Documentation and Examples

⬆️ Version Bumps

v1.0.0.0-RC19

22 Dec 05:25
ce9afac
Compare
Choose a tag to compare

Changes

✨ Features

🚀 Improvements

🐛 Bug Fixes

🧰 Maintenance

📓 Documentation and Examples

⬆️ Version Bumps

v1.0.0.0-RC18

09 Dec 11:54
Compare
Choose a tag to compare

Changes

Highlights

This release packs server-side cookie support, middleware support and endpoints to make your apis typesafe.

Server Side Cookie Support

private val cookie = Cookie("org", "d11") @@ maxAge(5 seconds)
val res            = Response.ok.addCookie(cookie)

private val app = Http.collect[Request] {
  case Method.GET -> !! / "cookie" =>
    Response.ok.addCookie(cookie @@ path(!! / "cookie") @@ httpOnly)

  case Method.GET -> !! / "secure-cookie" =>
    Response.ok.addCookie(cookie @@ secure @@ path(!! / "secure-cookie"))

  case Method.GET -> !! / "cookie" / "remove" =>
    res.addCookie(cookie.clear)
}

Middleware Support

val app: HttpApp[Clock, Nothing] = Http.collectM[Request] {
  // this will return result instantly
  case Method.GET -> !! / "text"         => ZIO.succeed(Response.text("Hello World!"))
  // this will return result after 5 seconds, so with 3 seconds timeout it will fail
  case Method.GET -> !! / "long-running" => ZIO.succeed(Response.text("Hello World!")).delay(5 seconds)
}

val serverTime: Middleware[Clock, Nothing] = patchM((_, _) =>
  for {
    currentMilliseconds <- currentTime(TimeUnit.MILLISECONDS)
    withHeader = Patch.addHeaders(List(Header("X-Time", currentMilliseconds.toString)))
  } yield withHeader,
)

val middlewares: Middleware[Console with Clock, IOException] =
  // print debug info about request and response
  debug ++
    // close connection if request takes more than 3 seconds
    timeout(3 seconds) ++
    // add static header
    addHeader("X-Environment", "Dev") ++
    // add dynamic header
    serverTime

Server.start(8090, (app @@ middlewares).silent).exitCode

Typesafe Endpoint Support

def app = GET / "a" / *[Int] / "b" / *[Boolean] to { a =>
  Response.text(a.params.toString)
}

🚀 Features

Improvements

🐛 Bug Fixes

🧰 Maintenance

📓 Documentation and Examples

📈 Version Bumps

v1.0.0.0-RC17

07 Jun 10:13
8467a6a
Compare
Choose a tag to compare

Changes

🚀 Features

🐛 Bug Fixes

🧰 Maintenance

v1.0.0.0-RC16

10 May 06:23
Compare
Choose a tag to compare

Changes

🚀 Features

Improvements

🐛 Bug Fixes

  • Fix: collectM unable to create more than 1 socket connection @tusharmath (#183)
  • Fix HttpResult compositional semantics @tusharmath (#169)
  • Fix netty exception: java.lang.IllegalStateException: unexpected message type: DefaultHttpResponse, state: 1 @amitksingh1490 (#154)

🧰 Maintenance