Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 05:52
    djspiewak commented #3293
  • 04:49
    jdaviderb starred http4s/http4s
  • 03:39
    rolandomanrique commented #3277
  • 03:33
    oandrew starred http4s/http4s
  • 02:37
    satorg commented #3277
  • Apr 04 22:43
    jadrouil starred http4s/http4s
  • Apr 04 21:57
    jordiolivares opened #3303
  • Apr 04 17:54
  • Apr 04 16:24

    rossabaker on 0.20

    http4s-0.20.21, scala-2.12.11 Oops, it's still 0.20.20 Merge pull request #136 from ht… (compare)

  • Apr 04 16:24
    rossabaker closed #136
  • Apr 04 16:24
    rossabaker commented #136
  • Apr 04 10:49
    qwerttyue starred http4s/http4s
  • Apr 04 10:49
    syte starred http4s/http4s
  • Apr 04 04:37

    rossabaker on gh-pages

    updated site (compare)

  • Apr 04 04:24

    rossabaker on master

    Update mergify rules for Scala … Merge pull request #3301 from r… (compare)

  • Apr 04 04:24
    rossabaker closed #3301
  • Apr 04 04:16
    rossabaker commented #3293
  • Apr 04 04:02
    rossabaker commented #3302
  • Apr 04 04:01

    rossabaker on master

    Update sbt-sonatype to 3.9.2 Merge pull request #392 from sc… (compare)

  • Apr 04 04:01
    rossabaker closed #392
Gavin Bisesi
@Daenyth
First, make an IOApp to be your main class
In that class you can call Jokes.impl[IO], and the implicits will all be in scope at that point. You can construct a client similarly
I may recommend not using the abstract F[_] approach if you're new to scala and don't have an experienced fp/cats/etc person to assist
instead just hardcode IO specifically - it can be changed later if you find it useful
hectarV
@hectarV
@Daenyth Thanks for the prompt response, tried this , i am not sure what am i missing here
mport java.util.concurrent.Executors
import cats._, cats.effect._, cats.implicits._
import cats.effect.{Blocker, ExitCode, IO, IOApp}
import org.http4s.client.blaze.BlazeClientBuilder
import org.http4s.client.{Client, JavaNetClientBuilder}
import cats._, cats.effect._, cats.implicits._
import scala.concurrent.ExecutionContext.global

object ClientInvoker extends IOApp {
  override def run(args: List[String]): IO[ExitCode] = {
    Jokes.impl[IO]
  }
}
Gavin Bisesi
@Daenyth
that shouldn't compile
hectarV
@hectarV
@Daenyth I guess i need to pass something else, not able to figure it out
Ross A. Baker
@rossabaker
Jokes.impl[IO] returns a Jokes[IO], which means a service to tell jokes that returns IO results.
runneeds to return an IO[ExitCode].
So Jokes.impl[IO].get would return you an IO[Jokes.Joke]. Now you've got a joke to do something with. But you still need to get to an ExitCode to represent whether the process succeeded or failed.
What do we do with the joke? Maybe we tell it with println: joke => IO(println(joke)). That's a Joke => IO[Unit]. And if we already have an IO[Joke], we can flatMap it to tell the joke.
Jokes.impl[IO].get.flatMap(joke => IO(println(joke)). Now we've got an IO[Unit], which represents the telling of the joke.
We did a flatMap to tell the joke, because telling the joke is something else that happens in IO, because println is a side effect.
Gavin Bisesi
@Daenyth
Really good answer :+1:
Ross A. Baker
@rossabaker
But IO[Unit] to IO[ExitCode] can be simpler: we can translate Unit => ExitCode without performing any side effects.
And if we have an IO[Unit], and a Unit => ExitCode, we can get to IO[ExitCode] by a simple map:
So, Jokes.impl[IO].get.flatMap(joke => IO(println(joke)).map(_ => ExitCode.Success). That should compile. (Maybe not, I'm just typing in Gitter. The compiler is the boss!)
From there, there are various things you can do to clean it up. Factor out the joke => IO(println(joke)) into a tellJoke(joke: Joke): IO[Unit]. Or .map(_ => ExitCode.Success) can be simplified to .as(ExitCode.Success).
But hopefully that rambling helps clarify some of the types, and how to get from what you have to what you need.
Probably the most confusing thing about that is why println needs to be wrapped in IO. The compiler is fine if you don't, but that's something that's important when you start to use Scala in a pure FP style. The cats.effect.IO docs have some deeper reading on "Why IO?"
Hopefully that helps. And if not, please ask more questions!
hectarV
@hectarV
@Ross thanks for detailed explanation, really appreciate this.
I feel terribly asking may be very basic things but i am really struggling with FP and Scala coming from Java world.
Tried below but it does not compile
  override def run(args: List[String]): IO[ExitCode] = {
    Jokes.impl[IO].get.flatMap(joke => IO(println(joke)).map(_ => ExitCode.Success)

  }
Charlie Hills
@contagnas
Looks to me like you're not passing a client to your Jokes.impl, you need something like
  override def run(args: List[String]): IO[ExitCode] = {
    BlazeClientBuilder[IO](global).resource.use { client =>
      Jokes.impl[IO](client).get.flatMap(joke => IO(println(joke))).map(_ => ExitCode.Success)
    }
Ross A. Baker
@rossabaker
Oops. That's what I get for typing in Gitter without compiling.
hectarV
@hectarV
@rossabaker Thanks Ross, it worked, Many many thanks
@Daenyth Thanks
hectarV
@hectarV
@contagnas Once i get the data by calling the Jokes.Impl , what is the best way of chaining it with another function which expects the parsed json
drocsid
@drocsid
If I want to change the log configuration in https://github.com/http4s/http4s.g8/blob/0.21/src/main/g8/src/main/resources/logback.xml but built an artifact using assembly can we provide that resource seperatly or do I have to rebuild the assembly?
Ross A. Baker
@rossabaker
@drocsid Configuring Java loggers has been a miserable process of trial and error for me for well over a decade, but I think you can set a system property to override the one in your assembly.
@hectarV The key concept is once you're in IO, you stay in IO. It's the responsibility of IOApp to finally run the IO that you produce.
If you have io: IO[A] and f: A => B, then io.map(f)is IO[B].
If you have io: IO[A] and f: A => IO[B], then io.flatMap(f) is IO[B].
Those are the two most common ways of "chaining". Note that if you map in the second case, you'd end up with IO[IO[B]], and you need to "flatten" that. Hence, "flatMap".
And if you're doing a lot of flatMaps in a chian (which is common), that's a good case for for-comprehensions.
Apologies if that's review. Not sure how long you've been studying Scala.
drocsid
@drocsid
@rossabaker thought I'd ask before jumping in. Thanks!
@rossabaker also I have another thing going. I'm deploying via native-image....
drocsid
@drocsid
looks like the native image isn't respecting it...
hectarV
@hectarV
@rossabaker Thanks a lot
Ross A. Baker
@rossabaker
@drocsid I'm not real fond of loading external resources like that anyway. I'd just rebuild the assembly. But I'm pretty sure there are also logback APIs to programmatically load the configuration.
hectarV
@hectarV
@rossabaker If the client API returns list of jokes, does the Entity decoder needs to be changed as well ?
Jose Emilio Labra Gayo
@labra
I have a service that acts as a proxy for another service which does a long process which can take a long time to return a response...is there an idiomatic way to increase the timeout?
Jose Emilio Labra Gayo
@labra
I am using BlazeClient
Jose Emilio Labra Gayo
@labra
I initialize the client with
      client <- BlazeClientBuilder[F](global).stream
and then I invoke the other service with something like:
 . . .
        postRequest = Request[F](method = POST, 
             uri = uri" . . .").
             withHeaders(`Content-Type`(MediaType.application.`json`)).
             withEntity[Json](jsonParams)
          result <- client.expect[Json](postRequest)
I noticed the BlazeClient constructor has several parameters like idleTimeout, requestTimeout and connectTimeout....I am not sure how to change those values and if I could, which one should I change
Jose Emilio Labra Gayo
@labra
I noticed that I could set the timeouts with .withConnectTimout methods and so on...
However, it still seems to ignore those settings...I gave values of several minutes and it always answers Response timed out after 30 seconds or so...
Tim Pigden
@TimPigden
Hi, is there a .20.x -> .21.x migration guide?
Tim Pigden
@TimPigden
In 20.x I was able to do the following to obtain both token and request from a post:
case AuthedRequest(authToken, req @ POST -> Root / "ageOf") =>
but AuthedRequest is no longer a case class. How do I capture both in my AuthedRoutes?