Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Drop toZIO and wrapZIO APIs #950

Merged
merged 2 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object WebSocketAdvanced extends App {

private val app =
Http.collectZIO[Request] {
case Method.GET -> !! / "greet" / name => Response.text(s"Greetings ${name}!").wrapZIO
case Method.GET -> !! / "greet" / name => UIO(Response.text(s"Greetings ${name}!"))
case Method.GET -> !! / "subscriptions" => socketApp.toResponse
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object WebSocketEcho extends App {

private val app =
Http.collectZIO[Request] {
case Method.GET -> !! / "greet" / name => Response.text(s"Greetings {$name}!").wrapZIO
case Method.GET -> !! / "greet" / name => UIO(Response.text(s"Greetings {$name}!"))
case Method.GET -> !! / "subscriptions" => socket.toResponse
}

Expand Down
8 changes: 4 additions & 4 deletions docs/website/docs/v1.x/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ val app = a <> b

### ZIO Integration

For creating effectful apps, you can use `collectZIO` and wrap `Response` using `wrapZIO` to produce ZIO effect value.
For creating effectful apps, you can use `collectZIO` and wrap `Response` with `UIO` to produce ZIO effect value.

```scala
val app = Http.collectZIO[Request] {
case Method.GET -> !! / "hello" => Response.text("Hello World").wrapZIO
case Method.GET -> !! / "hello" => UIO(Response.text("Hello World"))
}
```

Expand All @@ -91,7 +91,7 @@ import zhttp.http._

val app = Http.collectZIO[Request] {
case req @ Method.GET -> !! / "fruits" / "a" =>
Response.text("URL:" + req.url.path.asString + " Headers: " + req.getHeaders).wrapZIO
UIO(Response.text("URL:" + req.url.path.asString + " Headers: " + req.getHeaders))
case req @ Method.POST -> !! / "fruits" / "a" =>
req.getBodyAsString.map(Response.text(_))
}
Expand Down Expand Up @@ -137,7 +137,7 @@ private val socket = Socket.collect[WebSocketFrame] { case WebSocketFrame.Text("
}

private val app = Http.collectZIO[Request] {
case Method.GET -> !! / "greet" / name => Response.text(s"Greetings {$name}!").wrapZIO
case Method.GET -> !! / "greet" / name => UIO(Response.text(s"Greetings {$name}!"))
case Method.GET -> !! / "ws" => socket.toResponse
}
```
Expand Down
2 changes: 1 addition & 1 deletion example/src/main/scala/example/WebSocketAdvanced.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ object WebSocketAdvanced extends App {

private val app =
Http.collectZIO[Request] {
case Method.GET -> !! / "greet" / name => Response.text(s"Greetings ${name}!").wrapZIO
case Method.GET -> !! / "greet" / name => UIO(Response.text(s"Greetings ${name}!"))
case Method.GET -> !! / "subscriptions" => socketApp.toResponse
}

Expand Down
4 changes: 2 additions & 2 deletions example/src/main/scala/example/WebSocketEcho.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import zhttp.service.Server
import zhttp.socket.{Socket, WebSocketFrame}
import zio.duration._
import zio.stream.ZStream
import zio.{App, ExitCode, Schedule, URIO}
import zio.{App, ExitCode, Schedule, UIO, URIO}

object WebSocketEcho extends App {
private val socket =
Expand All @@ -19,7 +19,7 @@ object WebSocketEcho extends App {

private val app =
Http.collectZIO[Request] {
case Method.GET -> !! / "greet" / name => Response.text(s"Greetings {$name}!").wrapZIO
case Method.GET -> !! / "greet" / name => UIO(Response.text(s"Greetings {$name}!"))
case Method.GET -> !! / "subscriptions" => socket.toResponse
}

Expand Down
10 changes: 0 additions & 10 deletions zio-http/src/main/scala/zhttp/http/Response.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ final case class Response private (
*/
def withServerTime: Response = self.copy(attribute = self.attribute.withServerTime)

/**
* Wraps the current response as a Http
*/
def toHttp: Http[Any, Nothing, Any, Response] = Http.succeed(self)

/**
* Wraps the current response into a ZIO
*/
def wrapZIO: UIO[Response] = UIO(self)

/**
* Extracts the body as ByteBuf
*/
Expand Down
2 changes: 1 addition & 1 deletion zio-http/src/test/scala/zhttp/http/ResponseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object ResponseSpec extends DefaultRunnableSpec {
) +
suite("toHttp")(
testM("should convert response to Http") {
val http = Response.ok.toHttp
val http = Http(Response.ok)
assertM(http(()))(equalTo(Response.ok))
},
),
Expand Down