Skip to content

Zhttp#1337

Merged
adamw merged 45 commits intomasterfrom
unknown repository
Jul 8, 2021
Merged

Zhttp#1337
adamw merged 45 commits intomasterfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Jun 24, 2021

No description provided.

@ghost ghost requested a review from adamw June 24, 2021 08:20
@ghost ghost assigned slabiakt Jun 24, 2021
@ghost ghost self-assigned this Jun 24, 2021
Comment thread build.sbt Outdated
"dev.zio" %% "zio-interop-cats" % Versions.zioInteropCats,
"io.d11" %% "zhttp" % "1.0.0.0-RC17")
)
.jvmPlatform(scalaVersions = scala2Versions)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe scala 3 would work as well?

Comment thread build.sbt Outdated
lazy val zioHttp: ProjectMatrix = (projectMatrix in file("server/zio-http"))
.settings(commonJvmSettings)
.settings(
name := "tapir-zio-http4",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name should be without 4 :)

Comment thread build.sbt Outdated
@@ -131,6 +131,7 @@ lazy val allAggregates = core.projectRefs ++
playServer.projectRefs ++
vertxServer.projectRefs ++
zioServer.projectRefs ++
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the zioServer name is misleading now. Maybe we could rename it to zioHttp4sServer?

route: Endpoint[I, Throwable, O, ZioStreams]
)(logic: I => RIO[R, O]): Http[R, Throwable, Request, Response[R, Throwable]] = {
Http.fromEffectFunction[Request] { req =>
implicit val interpret: ZHttpBodyListener[R] = new ZHttpBodyListener[R]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name seems wrong?

}
}

private[zhttp] def zioMonadError[R]: MonadError[RIO[R, *]] = new MonadError[RIO[R, *]] {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's already one in sttp.tapir.server.http4s.ztapir. Maybe we could move it to the integrations/zio module and use the same implementation in both places?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah it was unused, nevermind then


def asByteArray: Task[Array[Byte]] = request.content match {
case HttpData.Empty => Task.succeed(Array.emptyByteArray)
case HttpData.CompleteData(data) => Task(data.toArray)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be Task.succeed as well, as we have a strict value?

@adamw
Copy link
Copy Markdown
Member

adamw commented Jun 25, 2021

Looks good so far :) Now tests ;)

One question - is it zhttp or zio-http? Would be good to keep one name in line with the server's name to avoid confusion

@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 25, 2021

From what I see project name is zio-http https://github.com/dream11/zio-http while package name is zhttp

@Fristi
Copy link
Copy Markdown

Fristi commented Jun 25, 2021

I see my commits are included, should I close #1150 if you like to follow up on my work ?

@adamw
Copy link
Copy Markdown
Member

adamw commented Jun 25, 2021

@bartekzylinski let's use zio-http consistently then

@adamw
Copy link
Copy Markdown
Member

adamw commented Jun 25, 2021

@Fristi yes, I think that @bartekzylinski and @slabiakt used your branch as a starting point. I suppose it's best to close the old PR :) Thanks for starting the work!

case RawBodyType.ByteArrayBody => asByteArray.map(RawValue(_))
case RawBodyType.ByteBufferBody => asByteArray.map(bytes => ByteBuffer.wrap(bytes)).map(RawValue(_))
case RawBodyType.InputStreamBody => asByteArray.map(new ByteArrayInputStream(_)).map(RawValue(_))
case RawBodyType.FileBody => Task.effect(RawValue(Defaults.createTempFile()))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we should return the created file as part of RawValue so that in case of an error, the file can be cleaned up


implicit val m: MonadError[RIO[Blocking, *]] = zioMonadError

new ServerBasicTests(createServerTest, interpreter, false, true, false, false).tests() ++
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] it's good practice to name boolean parameters. I think IntelliJ has an inspection for that as well

@adamw
Copy link
Copy Markdown
Member

adamw commented Jul 3, 2021

Thanks - looks good :) One thing that's missing is documentation - similar as for the other interpreters.

package sttp.tapir.server.ziohttp

import cats.data.NonEmptyList
import cats.effect.{Async, IO, Resource}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know a ZIO module needs Cats :)

}

override def server(routes: NonEmptyList[Http[Blocking, Throwable, Request, Response[Blocking, Throwable]]]): Resource[IO, Port] = {
val as: Async[IO] = Async[IO]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason we need Cats' Async here?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's just a test module but I'm just curious.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "test framework" for testing server interpreters is written using cats-effect, hence all of the interpreters use it (be it akka, cats, serverless, vertx, play or zio). This doesn't influence the implementation in any way, though.

@adamw adamw merged commit b0b9653 into softwaremill:master Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants