Skip to content

Commit

Permalink
upgrade zio version to 2.0.0-RC4(#1178)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgfraser authored Apr 2, 2022
1 parent e2e3561 commit a320cca
Show file tree
Hide file tree
Showing 73 changed files with 130 additions and 162 deletions.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ import zio.test._
import zhttp.test._
import zhttp.http._

object Spec extends DefaultRunnableSpec {
object Spec extends ZIOSpecDefault {
val app = Http.collect[Request] {
case Method.GET -> Root / "text" => Response.text("Hello World!")
}
Expand Down
2 changes: 1 addition & 1 deletion docs/website/docs/v1.x/dsl/cookies.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ To sign all the cookies in your `HttpApp`, you can use `signCookies` middleware:
}

// Run it like any simple app
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app @@ signCookies("secret")).exitCode
```

Expand Down
2 changes: 1 addition & 1 deletion docs/website/docs/v1.x/dsl/cookies/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ To sign all the cookies in your `HttpApp`, you can use `signCookies` middleware:
}

// Run it like any simple app
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app @@ signCookies("secret")).exitCode
```

Expand Down
4 changes: 2 additions & 2 deletions docs/website/docs/v1.x/dsl/headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ On the Server-side you can read Request headers as given below
import zio.stream.ZStream

object SimpleResponseDispatcher extends App {
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {

// Starting the server (for more advanced startup configuration checkout `HelloWorldAdvanced`)
Server.start(8090, app.silent).exitCode
Expand Down Expand Up @@ -155,7 +155,7 @@ val responseHeaders: Task[Headers] = Client.request(url).map(_.headers)
_ <- Console.printLine { data }
} yield ()

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = program.exitCode.provideCustomLayer(env)
override def run(args: List[String]): URIO[Any, ExitCode] = program.exitCode.provideLayer(env)

}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/website/docs/v1.x/dsl/headers/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ On the Server-side you can read Request headers as given below
import zio.stream.ZStream

object SimpleResponseDispatcher extends App {
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {

// Starting the server (for more advanced startup configuration checkout `HelloWorldAdvanced`)
Server.start(8090, app.silent).exitCode
Expand Down Expand Up @@ -152,7 +152,7 @@ val responseHeaders: Task[Headers] = Client.request(url).map(_.headers)
_ <- Console.printLine { data }
} yield ()

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = program.exitCode.provideCustomLayer(env)
override def run(args: List[String]): URIO[Any, ExitCode] = program.exitCode.provideLayer(env)

}
```
Expand Down
15 changes: 2 additions & 13 deletions docs/website/docs/v1.x/dsl/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,6 @@ application.

There are many operators to provide the HTTP application with its required environment.

### provideCustomLayer

Provides the HTTP application with the part of the environment that is not part of the ZEnv, leaving an effect that only depends on the ZEnv.

```scala
val a: Http[Clock, DateTimeException, String, OffsetDateTime] = Http.collectZIO[String] {
case "case 1" => clock.currentDateTime
}
val app: Http[zio.ZEnv, DateTimeException, String, OffsetDateTime] = a.provideCustomLayer(Clock.live)
```

## Attaching Middleware

Middlewares are essentially transformations that one can apply to any `Http` to produce a new one. To attach middleware to the HTTP application, you can use `middleware` operator. `@@` is an alias for `middleware`.
Expand All @@ -226,7 +215,7 @@ The below snippet tests an app that takes `Int` as input and responds by adding
import zio.test.Assertion.equalTo
import zio.test._

object Spec extends DefaultRunnableSpec {
object Spec extends ZIOSpecDefault {

def spec = suite("http")(
testM("1 + 1 = 2") {
Expand Down Expand Up @@ -365,6 +354,6 @@ We can use `Server.app()` method to bootstrap the server with an `HttpApp[R,E]`

object HelloWorld extends App {
val app: HttpApp[Any, Nothing] = Http.ok
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = Server.start(8090, app).exitCode
override def run(args: List[String]): UIO[ExitCode] = Server.start(8090, app).exitCode
}
```
15 changes: 2 additions & 13 deletions docs/website/docs/v1.x/dsl/http/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,6 @@ application.

There are many operators to provide the HTTP application with its required environment.

### provideCustomLayer

Provides the HTTP application with the part of the environment that is not part of the ZEnv, leaving an effect that only depends on the ZEnv.

```scala
val a: Http[Clock, DateTimeException, String, OffsetDateTime] = Http.collectZIO[String] {
case "case 1" => clock.currentDateTime
}
val app: Http[zio.ZEnv, DateTimeException, String, OffsetDateTime] = a.provideCustomLayer(Clock.live)
```

## Attaching Middleware

Middlewares are essentially transformations that one can apply to any `Http` to produce a new one. To attach middleware to the HTTP application, you can use `middleware` operator. `@@` is an alias for `middleware`.
Expand All @@ -223,7 +212,7 @@ The below snippet tests an app that takes `Int` as input and responds by adding
import zio.test.Assertion.equalTo
import zio.test._

object Spec extends DefaultRunnableSpec {
object Spec extends ZIOSpecDefault {

def spec = suite("http")(
test("1 + 1 = 2") {
Expand Down Expand Up @@ -362,6 +351,6 @@ We can use `Server.app()` method to bootstrap the server with an `HttpApp[R,E]`

object HelloWorld extends App {
val app: HttpApp[Any, Nothing] = Http.ok
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = Server.start(8090, app).exitCode
override def run(args: List[String]): UIO[ExitCode] = Server.start(8090, app).exitCode
}
```
10 changes: 5 additions & 5 deletions docs/website/docs/v1.x/dsl/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This section describes, ZIO HTTP Server and different configurations you can pro

## Start a ZIO HTTP Server with default configurations
```scala
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app.silent).exitCode
```
## Start a ZIO HTTP Server with custom configurations.
Expand All @@ -28,12 +28,12 @@ This section describes, ZIO HTTP Server and different configurations you can pro
```
3. And then use ```Server.make``` to get a "managed" instance use it to run a server forever
```scala
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {
server.make
.use(start =>
console.putStrLn(s"Server started on port ${start.port}")
*> ZIO.never,
).provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(2))
).provideLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(2))
.exitCode
```
**Tip :** `ServerChannelFactory.auto ++ EventLoopGroup.auto(num Threads)` is supplied as an external dependency to choose netty transport type. One can leave it as `auto` to let the application handle it for you.
Expand Down Expand Up @@ -76,7 +76,7 @@ object HelloWorldAdvanced extends App {
Server.paranoidLeakDetection ++ // Paranoid leak detection (affects performance)
Server.app(fooBar +++ app) // Setup the Http app

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {
// Configure thread count using CLI
val nThreads: Int = args.headOption.flatMap(x => Try(x.toInt).toOption).getOrElse(0)

Expand All @@ -89,7 +89,7 @@ object HelloWorldAdvanced extends App {
// Ensures the server doesn't die after printing
*> ZIO.never,
)
.provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(nThreads))
.provideLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(nThreads))
.exitCode
}
}
Expand Down
10 changes: 5 additions & 5 deletions docs/website/docs/v1.x/dsl/server/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This section describes, ZIO HTTP Server and different configurations you can pro

## Start a ZIO HTTP Server with default configurations
```scala
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app.silent).exitCode
```
## Start a ZIO HTTP Server with custom configurations.
Expand All @@ -25,12 +25,12 @@ This section describes, ZIO HTTP Server and different configurations you can pro
```
3. And then use ```Server.make``` to get a "managed" instance use it to run a server forever
```scala
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {
server.make
.use(start =>
Console.printLine(s"Server started on port ${start.port}")
*> ZIO.never,
).provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(2))
).provideLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(2))
.exitCode
```
**Tip :** `ServerChannelFactory.auto ++ EventLoopGroup.auto(num Threads)` is supplied as an external dependency to choose netty transport type. One can leave it as `auto` to let the application handle it for you.
Expand Down Expand Up @@ -73,7 +73,7 @@ object HelloWorldAdvanced extends App {
Server.paranoidLeakDetection ++ // Paranoid leak detection (affects performance)
Server.app(fooBar +++ app) // Setup the Http app

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {
// Configure thread count using CLI
val nThreads: Int = args.headOption.flatMap(x => Try(x.toInt).toOption).getOrElse(0)

Expand All @@ -86,7 +86,7 @@ object HelloWorldAdvanced extends App {
// Ensures the server doesn't die after printing
*> ZIO.never,
)
.provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(nThreads))
.provideLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(nThreads))
.exitCode
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object HelloWorldAdvanced extends App {
Server.paranoidLeakDetection ++ // Paranoid leak detection (affects performance)
Server.app(fooBar ++ app) // Setup the Http app

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {
// Configure thread count using CLI
val nThreads: Int = args.headOption.flatMap(x => Try(x.toInt).toOption).getOrElse(0)

Expand All @@ -40,7 +40,7 @@ object HelloWorldAdvanced extends App {
// Ensures the server doesn't die after printing
*> ZIO.never,
)
.provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(nThreads))
.provideLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(nThreads))
.exitCode
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object ConcreteEntity extends App {
.map(userCreated => Response.text(userCreated.id.toString)) // Http[Any, Nothing, Request, Response]

// Run it like any simple app
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app).exitCode
}

Expand Down
2 changes: 1 addition & 1 deletion docs/website/docs/v1.x/examples/advanced-examples/cors.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object HelloWorldWithCORS extends App {
} @@ cors(config)

// Run it like any simple app
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app.silent).exitCode
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object BasicAuth extends App {
val app: UHttpApp = user @@ basicAuth("admin", "admin")

// Run it like any simple app
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app).exitCode
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object HelloWorldWithCORS extends App {
} @@ cors(config)

// Run it like any simple app
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app.silent).exitCode
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object CSRF extends App {
} @@ csrfGenerate() // set x-csrf token cookie

val app = publicApp ++ privateApp
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app).exitCode
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ object FileStreaming extends App {
}

// Run it like any simple app
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app.silent).exitCode
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import zio._
* Example to encode content using a ZStream
*/
object StreamingResponse extends App {
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {

// Starting the server (for more advanced startup configuration checkout `HelloWorldAdvanced`)
Server.start(8090, app.silent).exitCode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ object WebSocketAdvanced extends App {
case Method.GET -> !! / "subscriptions" => socketApp.toResponse
}

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app).exitCode
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ object SimpleClient extends App {
_ <- Console.printLine { data }
} yield ()

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
program.exitCode.provideCustomLayer(env)
override def run(args: List[String]): UIO[ExitCode] =
program.exitCode.provideLayer(env)

}
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object HelloWorld extends App {
}

// Run it like any simple app
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app.silent).exitCode
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ object HttpsHelloWorld extends App {
ServerSSLOptions(sslctx, SSLHttpBehaviour.Accept),
)

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {
server.make.useForever
.provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(0))
.provideLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(0))
.exitCode
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ object HttpsClient extends App {
_ <- console.putStrLn { data }
} yield ()

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode]
= program.exitCode.provideCustomLayer(env)
override def run(args: List[String]): UIO[ExitCode]
= program.exitCode.provideLayer(env)

}
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ object HttpsHelloWorld extends App {
ServerSSLOptions(sslctx, SSLHttpBehaviour.Accept),
)

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] = {
override def run(args: List[String]): UIO[ExitCode] = {
server.make.useForever
.provideCustomLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(0))
.provideLayer(ServerChannelFactory.auto ++ EventLoopGroup.auto(0))
.exitCode
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ object WebSocketEcho extends App {
case Method.GET -> !! / "subscriptions" => socket.toResponse
}

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): UIO[ExitCode] =
Server.start(8090, app).exitCode
}

Expand Down
4 changes: 2 additions & 2 deletions docs/website/docs/v1.x/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Since `Http` is a function of the form `A => ZIO[R, Option[E], B]` to test it yo
import zio.test._
import zhttp.http._

object Spec extends DefaultRunnableSpec {
object Spec extends ZIOSpecDefault {

def spec = suite("http")(
testM("should be ok") {
Expand Down Expand Up @@ -159,7 +159,7 @@ import zio._
object HelloWorld extends App {
val app = Http.ok

override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
override def run(args: List[String]): URIO[Any, ExitCode] =
Server.start(8090, app).exitCode
}
```
Expand Down
Loading

0 comments on commit a320cca

Please sign in to comment.