github zio/zio-http v1.0.0.0-RC25

latest releases: v3.0.1, v3.0.0, v3.0.0-RC10...
2 years ago

Changes

Highlights

  • Support for Static Server
    ZIO-HTTP now provides support for building static servers with a very simple DSL.

    // A simple app to serve static resource files from a local directory.
    val app = Http.collectHttp[Request] { case Method.GET -> "static" /: path =>
        for {
        file <- Http.getResourceAsFile(path.encode)
        http <-
            // Rendering a custom UI to list all the files in the directory
            if (file.isDirectory) {
    
            // Accessing the files in the directory
            val files = file.listFiles.toList.sortBy(_.getName)
            val base  = "/static"
            val rest  = path.dropLast(1)
    
            // Custom UI to list all the files in the directory
            Http.template(s"File Explorer ~$base${path}") {
                ul(
                li(a(href := s"$base$rest", "..")),
                files.map { file =>
                    li(
                    a(
                        href := s"$base${path.encode}${if (path.isEnd) file.getName else "/" + file.getName}",
                        file.getName,
                    ),
                    )
                },
                )
            }
            }
    
            // Return the file if it's a static resource
            else if (file.isFile) Http.fromFile(file)
    
            // Return a 404 if the file doesn't exist
            else Http.empty
        } yield http
    }
  • New Http.attempt operator
    Attempts to create an Http that succeeds with the provided value, capturing all exceptions on it's way.

    val app = Http.attempt(throw throwable).execute(())

💥 Breaking Changes

  • Rename provide and provideSome in Http and Socket domains
    Previous Current
    provide provideEnvironment
    provideSome provideSomeEnvironment

🚀 Features

Improvements

🐛 Bug Fixes

🧰 Maintenance

Full Changelog: v1.0.0.0-RC24...v2.0.0

Don't miss a new zio-http release

NewReleases is sending notifications on new releases.