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

Require an http4s client to provide more flexibility #373

Merged
merged 2 commits into from Mar 17, 2020
Merged

Conversation

BenFradet
Copy link
Contributor

@BenFradet BenFradet commented Mar 16, 2020

This change avoids creating and tearing down a client on each call.

If this looks okay, I'll modify the docs as well.

cc @tovbinm

Copy link

@tovbinm tovbinm left a comment

Choose a reason for hiding this comment

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

Thank you!!

@BenFradet BenFradet force-pushed the reuse-client branch 2 times, most recently from f8534ae to c754d14 Compare March 17, 2020 10:17
@codecov-io
Copy link

Codecov Report

Merging #373 into master will decrease coverage by 0.05%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #373      +/-   ##
==========================================
- Coverage   92.71%   92.65%   -0.06%     
==========================================
  Files          23       23              
  Lines         535      531       -4     
  Branches        1        2       +1     
==========================================
- Hits          496      492       -4     
  Misses         39       39
Impacted Files Coverage Δ
...la/github4s/interpreters/ProjectsInterpreter.scala 100% <ø> (ø) ⬆️
...4s/src/main/scala/github4s/http/Http4sSyntax.scala 100% <ø> (ø) ⬆️
...ub4s/src/main/scala/github4s/http/HttpClient.scala 92.85% <100%> (-0.9%) ⬇️
...s/src/main/scala/github4s/modules/GithubAPIs.scala 100% <100%> (ø) ⬆️
github4s/src/main/scala/github4s/Github.scala 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e28ba8...c754d14. Read the comment docs.

@cb372
Copy link
Member

cb372 commented Mar 17, 2020

This change avoids creating and tearing down a client on each call.

I haven't looked in detail but that might help with 47degrees/sbt-microsites#398

```

`user1` in this case is a `IO[GHResponse[User]]`.

### Using `F[_]: cats.effect.ConcurrentEffect`
### Using `F[_]: cats.effect.Sync`
Copy link
Member

Choose a reason for hiding this comment

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

The actual context bound in the sample code below is : Async: ContextShift

Copy link
Contributor Author

@BenFradet BenFradet Mar 17, 2020

Choose a reason for hiding this comment

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

This is because of the chosen client, if it were BlazeClientBuilder it would be ConcurrentEffect. Our constraint is actually Sync: https://github.com/47degrees/github4s/pull/373/files#diff-9a35e1db598f031cb40b6fcaf7266225R24. Do you think this needs additional information / explanation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

or I could write the example as:

  def u1[F[_]: Sync](httpClient: Client[F]): F[GHResponse[User]] =
    Github[F](httpClient, accessToken).users.get("juanpedromoreno")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

which might be closer to what people end up writing anyway

) {

private lazy val module: GithubAPIs[F] =
new GithubAPIv3[F](accessToken, timeout.getOrElse(Duration(1000L, MILLISECONDS)))
new GithubAPIv3[F](client, accessToken)

lazy val users: Users[F] = module.users
Copy link
Member

Choose a reason for hiding this comment

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

Not related to this PR, but is there any reason for all this stuff to be lazy?

Copy link
Contributor Author

@BenFradet BenFradet Mar 17, 2020

Choose a reason for hiding this comment

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

I guess if you're using only one module / set of apis, the others don't get evaluated? 🤔

.setThreadSub(validThreadId, true, false, headerUserAgent)
.unsafeRunSync()
val response = client
.use { client =>
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use a short name like c here, or rename the client in BaseIntegrationSpec to clientResource or something like, to avoid shadowing?

Copy link
Member

@cb372 cb372 left a comment

Choose a reason for hiding this comment

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

Looks great! Just a couple of minor comments

@BenFradet BenFradet merged commit 6f22e39 into master Mar 17, 2020
@BenFradet BenFradet deleted the reuse-client branch March 17, 2020 13:23
@juanpedromoreno juanpedromoreno added the breaking-change A breaking change that needs to be treated with consideration label Apr 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change A breaking change that needs to be treated with consideration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants