-
Notifications
You must be signed in to change notification settings - Fork 787
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
Deprecate Client#fetch #3345
Comments
@rossabaker the link to my comment points to Chris twitter as well |
Semi-related to #2738 because the |
Am I correct in understanding your opposition to In other words, it's better to deal with |
Yes. |
Is another benefit, @rossabaker, in deprecating Imports@ import $ivy.`org.http4s::http4s-circe:0.20.19`
import $ivy.$
@ import $ivy.`org.http4s::http4s-core:0.20.19`
import $ivy.$
@ import $ivy.`org.http4s::http4s-client:0.20.19`
import $ivy.$
@ import org.http4s._
@ import org.http4s.client._
@ import org.http4s.circe._
@ import io.circe.Json IO@ for {
resp <- client.fetch(Request[IO]()) { resp: Response[IO] => IO { resp } }
json1 <- resp.as[Json]
json2 <- resp.as[Json]
} yield Json.fromValues(List(json1, json2))
res26: IO[Json] = Bind(
Bind(
Map(Delay(cats.effect.concurrent.Ref$$$Lambda$3047/864102782@30bee87a), org.http4s.client.Client$$$Lambda$3048/2058221393@39cd953c, 0),
cats.effect.Resource$$Lambda$3094/1466001486@300ce687
),
ammonite.$sess.cmd26$$$Lambda$3268/181218042@5f342596
)
@ res26.unsafeRunSync
java.io.IOException: response was disposed
... Resource@ val client: Client[IO] = Client.fromHttpApp[IO] { HttpApp { case _ => Response[IO](status = Status.Ok).withBody(Json.obj( ("hi", Json.fromString("world")) ) ) } }
client: Client[IO] = org.http4s.client.Client$$anon$1@3627bfdd
@ for {
resp <- client.run(Request[IO]())
json1 <- Resource.liftF(resp.as[Json])
json2 <- Resource.liftF(resp.as[Json])
} yield Json.fromValues(List(json1, json2))
res20: Resource[IO, Json] = Bind(
Suspend(Map(Delay(cats.effect.concurrent.Ref$$$Lambda$3047/864102782@6424c975), org.http4s.client.Client$$$Lambda$3048/2058221393@76604521, 0)),
ammonite.$sess.cmd20$$$Lambda$3246/181734605@2e045d26
)
@ res20.use { json => IO(println(json.spaces2)) }.unsafeRunSync
[
{
"hi" : "world"
},
{
"hi" : "world"
}
] |
@rossabaker, btw, some time ago I asked about those def fetch[A](req: F[Request[F]])(f: Response[F] => F[A]): F[A]
def expectOr[A](req: F[Request[F]])(onError: Response[F] => F[Throwable])(implicit d: EntityDecoder[F, A]): F[A]
def expect[A](req: F[Request[F]])(implicit d: EntityDecoder[F, A]): F[A]
def fetchAs[A](req: F[Request[F]])(implicit d: EntityDecoder[F, A]): F[A]
def status(req: F[Request[F]]): F[Status]
def successful(req: F[Request[F]]): F[Boolean] And you agreed that they aren't really useful anymore. Do you think it could be right time to deprecate them too as part of this effort? |
@kevinmeredith The problem with your @satorg I'd like to remove them, but it's been pointed out that the client DSL still returns requests in |
Thanks for that explanation, @rossabaker
If I understand properly, the anti-pattern of |
Exactly that. Generically, |
Hey guys, would you mind if I take on this issue? If no one did it already of course... |
@satorg It's yours! |
@rossabaker what's the version this fix will go to? I need some value to put into |
Great question.
I think series/0.21 and 0.21.4 is good, and we should see if we can get a volunteer to dust off the scalafix machinery. |
So far so good. Meanwhile there're a bunch of other suspicious (for the same reason as
Also there're a few methods that take
@rossabaker, @ChristopherDavenport, @SystemFw, @kevinmeredith any thoughts? |
I agree with your idea, @satorg. The benefit of deprecating 4-8 would be to reduce the surface area of the |
Sorry, I overlooked @satorg's followup. I agree with @kevinmeredith. These were in questionable taste, but convenient, when encoding was effectful. Now that it's not, they are much less compelling. Note that the client DSL still returns |
@rossabaker yes, I agree that the client DSL should be changed accordingly. |
fetch is done, but leaving open to discuss @satorg's proposal to go further. |
@rossabaker would it make sense to create a separate issue for deprecating methods that take |
Yes, as long as we link it to this one to continue the context, that would be better. |
As far as I can see, this issue might be closed since the proposed work is done. |
@ChristopherDavenport has been arguing for this, and I like @SystemFw's argument about not burying
use
.Steps:
@deprecated
annotation to both overloads ofClient.fetch
.client.fetch(req)(f)
withclient.run(req).use(f)
in tests and docs.Bonus step 1.5, but more difficult: Implement a scalafix rule. Would make step 2 easier, and will help a lot of people upgrading.
The text was updated successfully, but these errors were encountered: