Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 07:58
    RaasAhsan commented #4929
  • 07:56
    RaasAhsan review_requested #4933
  • 07:56
    RaasAhsan labeled #4933
  • 07:56
    RaasAhsan opened #4933
  • Jun 19 02:25
    valencik opened #4932
  • Jun 19 01:46
    valencik opened #4931
  • Jun 18 23:26
    nolledge commented #4922
  • Jun 18 23:25
    nolledge opened #4930
  • Jun 18 23:16
  • Jun 18 20:00
    jrozanski starred http4s/http4s
  • Jun 18 15:28
    vimitdhawan opened #4929
  • Jun 18 06:28

    mergify[bot] on main

    Update slf4j-api to 1.7.31 Merge pull request #4928 from s… (compare)

  • Jun 18 06:28
    mergify[bot] closed #4928
  • Jun 18 06:17
    scala-steward opened #4928
  • Jun 17 02:41
    rossabaker closed #4926
  • Jun 17 02:41
    rossabaker commented #4926
  • Jun 17 02:39

    rossabaker on main

    Use MUnit in ActorSuite Use MUnit in BufferToolsSuite Use MUnit in ExecutionSuite and 18 more (compare)

  • Jun 17 02:39
    rossabaker closed #539
  • Jun 17 02:39
    rossabaker commented #539
  • Jun 16 16:47

    mergify[bot] on main

    Update metrics-core, metrics-js… Merge pull request #4927 from s… (compare)

Carlos Verdes
@carlos-verdes
    IO({
      println("running something!!")
      ExitCode.Success
    })
but if I put this... the app just exit
    BlazeServerBuilder[IO](executionContext)
        .bindHttp(serverConfig.port, serverConfig.host)
        .withHttpApp(app)
        .resource
        .use(_ => IO.never)
        .start
        .as(ExitCode.Success)
running with sbt run it works
Swoorup Joshi
@Swoorup
is there any way to do websocket JSON streaming over http4s?
Would that just be converting via scala object => json => string => Text?
Anton Sviridov
@velvetbaldmime:matrix.org
[m]

Would that just be converting via scala object => json => string => Text?

yep

Swoorup Joshi
@Swoorup
cool.
lmeyer
@LeonardMeyer

Is it possible to do something like this in my test :

  val routes = HttpRoutes
    .of[Id] { case _ =>
      Ok(AccessTokenResponse("token", "bearer", 3600, "openid"))
    }
    .orNotFound

Apparently Ok creates an IO and I don't know how to make it work. If it's even possible. It says it wants an Id[Response[Id]] when I give it IO[Response[IO]]

Oh actually I can't even test my service talking to this route because Id doesn't have instance forTemporal and Concurrent. Nevermind I guess
daenyth
@daenyth:matrix.org
[m]
You can use IO in tests; see the website
You'd use .of[IO] in this case
lmeyer
@LeonardMeyer
Yes that's what I ended up doing. Basically when you use cats-effect you tend not to test with Id right ?
daenyth
@daenyth:matrix.org
[m]
No, Id can't be used to represent side-effecting computations
Carlos Verdes
@carlos-verdes
So running the application with sbt run works (server is running) but running with java -jar the code of my IOApp just exit with code 0
anyone had this issue?
Carlos Verdes
@carlos-verdes
I found the problem... no issues :)
Maatary
@Maatary

Hi, Just starting with Http4s, and right now I'm looking for examples that shows the different ways to use encoders. In the official doc, the only example shown is for decoder only

println(response.flatMap(_.as[Resp]).unsafeRunSync)

could anyone point me to some examples that could help with this please ?

Rohan Sircar
@rohan-sircar
@Maatary you mean EntityEncoder right?
Maatary
@Maatary
Yes
My bad
Rohan Sircar
@rohan-sircar
ok
You can summon an EntityEncoder for a type with the partially-applied apply method
val s = "foo"
EntityEncoder[F, String].toEntity(s) // Entity[F]
if you're using the http4s dsl, the response methods like Ok(..) do this automatically
Maatary
@Maatary
nice thank you
Sheng-Loong Su
@code_ssl_twitter
Hi, is there a way to print all available route details for debugging purposes?
Maatary
@Maatary

Hi, I am trying to send a Post Request as MultiPart Data. The difference with the examples provided in the repo, is that, i need to send the data from inputStreams that i do have in memory.

There is a function for that but it is not exposed publicly, and to be fair i do not really understand very well the reason explained in the comment. Ultimately, i ended reproducing the function externally for my use case.

object Part {
....

  // The InputStream is passed by name, and we open it in the by-name
  // argument in callers, so we can avoid lifting into an effect.  Exposing
  // this API publicly would invite unsafe use, and the `EntityBody` version
  // should be safe.
  private def fileData[F[_]](
      name: String,
      filename: String,
      in: => InputStream,
      headers: Header.ToRaw*)(implicit F: Sync[F]): Part[F] =
    fileData(name, filename, readInputStream(F.delay(in), ChunkSize), headers: _*)
}

What I ended doing in my code is:

def inputStreamAsFileData[F[_]](name: String, filename: String, in: => InputStream, headers: Header.ToRaw*) (implicit F: Sync[F]): Part[F] = {
  val ChunkSize = 8192
  fileData(name, filename, readInputStream(F.delay(in), ChunkSize), headers: _*)
}

Hence my question is, what would be the unsafe way to use that function actually ? Just to make sure that i do not do anything i should not do ?

Rohan Sircar
@rohan-sircar
@Maatary InputStream is mutable/not referentially transparent/have a lifetime. In those methods it cannot be said in what state the InputStream is in by the time they are called so they're both unsafe.
The former method gets around it by the fact that it is private so the author themselves are responsible that it is used properly. But for public methods, that inputStream would be taken as an in: IO[InputStream] argument.
Rohan Sircar
@rohan-sircar
so the creation of the inputStream that is passed has to be wrapped in IO. It serves as a factory here. This is what the comment means by lifting into an effect.
as to the problem in hand, do you really need to use InputStream here? You could use something from fs2-io. That's going to be safe.
Maatary
@Maatary
@rohan-sircar Thank you so much for the detail explanation. Very Clear.
On the second point, well, i am in my journey in making the most of the TypeLevel Stack. I started working with cats-effects and IO and all, about 2 months ago. So far i am using doobie, Cats-effect effectively, and now working on http4s, and slowly getting to fs2. So i guess change will be incremental, as it is a lot to take in.
Maatary
@Maatary
This being said, i will have a look about at substituting my use of inputStream with fs2. The thing is tho, i am using a legacy java api (Apache Jena), that do rely on java InputStreams and OutputStreams. So i have to work with it. And from what i picked up with fs2-io, readInputStream(F.delay(in), ChunkSize) make use of the interop capability of it.
Rohan Sircar
@rohan-sircar
I'm a fellow journeyman too, just started a bit earlier :D . I agree on the incremental change as I've been through it myself but it's definitely worth it.
didnt realize readInputStream is from fs2-io. I missed a crucial portion in my answer - you need to wrap the creation of the inputStream in IO, so that it is created every time it is needed.
basically
val in = F.delay(new Inputstream(..))
readInputStream(in, ChunkSize), headers: _*)
there is no benefit in doing this, we're back to square one
val in = new Inputstream(..)
readInputStream(F.delay(in), ChunkSize), headers: _*)
Maatary
@Maatary
@rohan-sircar AH YES !!! Good One !!! Thanks for this. Will Make the change to my function accordingly !!!
vikasdp
@vikasdp
is there a way to integrate spring and initialize spring managed beans into an app that’s written in http4s? (vendor lib so can’t control/avoid spring beans for calling some vendor utility from http4s app)
Gabriel Volpe
@gvolpe:matrix.org
[m]
Hi folks, just reporting that the documentation style seems broken in v1.0: https://http4s.org/v1.0/ . Looks fine in other versions.
Vimit Dhawan
@vimitdhawan
Hi Everyone, we are doing performance testing on our application and we are getting this error even at 1 rps(1-2%).
org.http4s.InvalidBodyException: Received premature EOF
if someone wants to see a specific configuration or more details, please let me know.
3 replies
Daniela Sfregola
@DanielaSfregola
Good morning http4s team! Quick question for you: how far are you from releasing http4s 0.22.0 (latest is 0.22.0-RC1 for the 0.22 series). Thanks!
pooriatgh
@pooriatgh
Hello everyone, Could give me some advice on my problem. I want to create a CSV file and send it as a response to API caller with Http4s. Is there any tutorial about this?
Eric Swenson
@eswenson1

I've defined authenticated routes with:

private val httpRoutes: AuthedRoutes[User, JobTask] = AuthedRoutes.of[User, JobTask] {

    case GET -> Root / ObjectIdVar(id) as user =>
...

Prior to adding authentication, I used this construct to add a prefix to the paths for all those routes:

// val routes: HttpRoutes[JobTask] = Router(
  //   prefixPath -> httpRoutes
  //)

Now, I want to do the same but can't use Router. What do I use instead?

val routes: AuthedRoutes[User, JobTask] = Router(
    prefixPath -> httpRoutes
  )

Doesn't compile.

Eric Swenson
@eswenson1
I worked around this by copying Router.scala and making an AuthedRouter that does the same thing, but I don't think this should be how one is supposed to solve this problem.
Tomas Klubal
@blondacz
Hello everyone,
Tomas Klubal
@blondacz
all the examples are using scala global ExecutionContext, if the Blaze server is run in the cats effect IO v 3 then the compute context is accessible via IORuntime#compute. Is that what should be used?