by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 19:42

    mergify[bot] on master

    Update sbt-mdoc to 2.2.4 Merge pull request #653 from sc… (compare)

  • 19:42
    mergify[bot] closed #653
  • 19:17
    scala-steward opened #653
  • 14:12
    adamw commented #650
  • 14:09
    user753 closed #650
  • 14:09
    user753 commented #650
  • 13:03

    adamw on v3

    Don't use >> (compare)

  • 12:32
    adamw commented #190
  • 09:53
    adamw commented #648
  • 09:53

    adamw on vversion

    (compare)

  • 09:52

    adamw on master

    Another release-drafter attempt (compare)

  • 09:48

    github-actions[bot] on vversion

    (compare)

  • 09:46

    softwaremill-ci on v2.2.4

    (compare)

  • 09:46

    softwaremill-ci on master

    Setting version to 2.2.4 (compare)

  • 08:49

    adamw on master

    Update dependencies (compare)

  • 08:33

    adamw on master

    Upgrade ZIO to 1.0.0 Fix example Merge pull request #648 from gh… (compare)

  • 08:33
    adamw closed #648
  • 08:32

    adamw on master

    Update zio-opentracing to 0.7.0 Merge pull request #647 from sc… (compare)

  • 08:32
    adamw closed #647
  • 08:32

    adamw on master

    Release-drafter, maybe this tim… (compare)

Gaarv
@Gaarv
I have case class with camel case and api with snake case (classic ^^), using json4s "manually" I can see how to do it but is there any way to pass a sttp serializer / deserializer to this same end ?
4 replies
Rhys Bradbury
@iRhysBradbury
Is there an example usage of the SttpBackendStub with a NoContent returned in the WhenRequest#thenRespond def?
For example
SttpBackendStub(new AsyncMonadAsyncError[Task]).whenRequestMatches(_ => true).thenRespond(
  //somethign here to represent NoContent
)
Rhys Bradbury
@iRhysBradbury
do you just use ?
.thenRespondWithCode(
        code = StatusCodes.NoContent
      )
1 reply
Rhys Bradbury
@iRhysBradbury
The default msg = "" is this the same as NoContent in SttpBackendStub
GRYE
@GRYE
hey
can anybody tell me, if I use HttpURLConnectionBackend (I just have to...), should I use only one instance per application, or I need an instance for every class that uses it?
2 replies
CodingPenguin
@TheCodingPenguin
Hello everyone I was wondering if there is an option to configure HTTPS Proxy in the following way:
implicit val sttpBackend: SttpBackend[Identity, Nothing, WebSocketHandler] = OkHttpSyncBackend(
        options = SttpBackendOptions.httpProxy()
      )
frobinet
@frobinet
Hi! I'm looking into WebSocketClient options on the ScalaJS side. I was wondering whether there is any good reason not to have the ZIO backend also published for ScalaJS, since ZIO itself is already available on SJS?
1 reply
Tom
@tarossi
Hi. Does anyone know if STTP uses persistent connections (in order to reuse them) or it just connects once for each request? Thanks
3 replies
CodingPenguin
@TheCodingPenguin
Hello everyone I'm getting the following error in a client where I'm sending a simple post request: any idea what it might be ?
sttp.client.SttpClientException$ReadException: java.net.SocketException: Unexpected end of file from server +details
sttp.client.SttpClientException$ReadException: java.net.SocketException: Unexpected end of file from server
    at sttp.client.SttpClientException$.defaultExceptionToSttpClientException(SttpClientException.scala:39)
    at sttp.client.HttpURLConnectionBackend.$anonfun$adjustExceptions$1(HttpURLConnectionBackend.scala:287)
    at sttp.client.SttpClientException$.adjustSynchronousExceptions(SttpClientException.scala:50)
    at sttp.client.HttpURLConnectionBackend.adjustExceptions(HttpURLConnectionBackend.scala:287)
    at sttp.client.HttpURLConnectionBackend.send(HttpURLConnectionBackend.scala:28)
    at sttp.client.HttpURLConnectionBackend.send(HttpURLConnectionBackend.scala:22)
    at sttp.client.FollowRedirectsBackend.sendWithCounter(FollowRedirectsBackend.scala:29)
    at sttp.client.FollowRedirectsBackend.send(FollowRedirectsBackend.scala:17)
2 replies
Nick Childers
@Voltir
I am a bit confused by the multipartBody documentation.. its not clear to me how to use it, or what the type parameter is supposed to be
Nick Childers
@Voltir
Also, the docs reference some "Multipart" class that doesnt seem to exist
Sean Kwak
@cosmir17

I have started using Cats effect (IO). Usually effect type 'IO' is stated in the main class and each component is to have [F[_]: Sync] type signature.
When I use the following Sttp dependency, 'IO' is to be stated in a Custom HttpClient class.
https://sttp.softwaremill.com/en/latest/backends/catseffect.html

I don't know how it's used in production code normally. Do people define implicit val cs: ContextShift[F] = IO.contextShift( scala.concurrent.ExecutionContext.global ) in the main class and pass it in to HttpClient class? Any advice for me?

ybasket
@ybasket
@cosmir17 You can’t define the ContextShift like that (with F in the type, but using IO). You can go with tagless final and have everything except your main class in F[_] or you use IO all the way down. In either way, use IOApp for your main class, then you get the ContextShift for free (it’s pre-defined there). Creating it yourself is usually only necessary in cases where the main isn’t yours, for example inside Play or Spark or so.
Sean Kwak
@cosmir17
Thank you, @ybasket. If I haven't misunderstood what you said, I get 'ContextShift' from IOApp used in Main class and provide it all the way down to my Custom Http Client (sttp).
ybasket
@ybasket
@cosmir17 Yes, exactly. Note that very often, you’ll want to initialize your sttp backend also in or close to your main class, so “all the way down” wouldn’t be too deep down
Sean Kwak
@cosmir17
@ybasket yes, I see. I then can pass my client instance to an apporpiate logic class.
Philipp Dörfler
@phdoerfler
Hi all! I just wanna say thank you to softwaremill for making this library! I love using it in my personal projects :)
1 reply
Leo Uzcategui
@leou
Hi - I am new to sttp and I like what I've tried so far. I read the usage example for spray-json in the Docs. I am not using a case class but I would like to know how to decode the response directly into a spray.json.JsObject, without having to parse the response body from a String into a JsObject. For example something like: basicRequest.get(...).response(asJson[???]).send()
What should ??? be? I've tried JsObject and JsValue but neither one works.
Is it possible to do this? Thanks in advance
3 replies
utkarsh2811
@utkarsh2811
image.png

Hello, I am trying to a simple synchronous post request using sttp and following https://sttp.softwaremill.com/en/stable/examples.html#post-a-form-using-the-synchronous-backend

but i get following error:

1 reply
am i missing any arguments that i must provide? cuz the doc doesnt say so.
Nick Childers
@Voltir

Im still having a bit of a hard time understanding how the multipart body part of the api is supposed to be used - ive tried mapping the input to

data: Seq[RawData]

and

case class FormThing(file:  Part[InputStream])
data: FormThing

In both cases they compile, but the resulting object isnt exactly what i expected - fields defined in Part / RawData like contentType and headers do not appear to be set.

1 reply
Nick Childers
@Voltir
I think there is a bug in this chunk of code (package sttp.tapir.server.akkahttp):
private def entityToRawValue[R](
      entity: HttpEntity,
      bodyType: RawBodyType[R],
      ctx: RequestContext
  )(
      implicit mat: Materializer,
      ec: ExecutionContext
  ): Future[R] = {
    bodyType match {
      case RawBodyType.StringBody(_)   => implicitly[FromEntityUnmarshaller[String]].apply(entity)
      case RawBodyType.ByteArrayBody   => implicitly[FromEntityUnmarshaller[Array[Byte]]].apply(entity)
      case RawBodyType.ByteBufferBody  => implicitly[FromEntityUnmarshaller[ByteString]].apply(entity).map(_.asByteBuffer)
      case RawBodyType.InputStreamBody => implicitly[FromEntityUnmarshaller[Array[Byte]]].apply(entity).map(new ByteArrayInputStream(_))
      case RawBodyType.FileBody =>
        serverOptions
          .createFile(ctx)
          .flatMap(file => entity.dataBytes.runWith(FileIO.toPath(file.toPath)).map(_ => file))
      case m: RawBodyType.MultipartBody =>
        implicitly[FromEntityUnmarshaller[Multipart.FormData]].apply(entity).flatMap { fd =>
          fd.parts
            .mapConcat(part => m.partType(part.name).map((part, _)).toList)
            .mapAsync[RawPart](1) { case (part, codecMeta) => toRawPart(part, codecMeta, ctx) }
            .runWith[Future[scala.collection.immutable.Seq[RawPart]]](Sink.seq)
            .asInstanceOf[Future[R]]
        }
    }
  }
1 reply
In particular, it doesnt appear that entity.contentType is ever accessed / copied into the rawPart
compared to the akka directive fileUpload, it has this line to pull out the FileInfo metadata:
 val data = (FileInfo(part.name, part.filename.get, part.entity.contentType), part.entity.dataBytes)
Viktor Lund
@vilu
This message was deleted
This message was deleted
Ixadias
@Ixadias
Anyone know if sttp supports custom uri decoding? I've got some funky url's using "__" in place of "&" for some query params, which causes sttp to significantly mutate the url when it encounters the subsequent "=".
1 reply
I'd like to be able to tell sttp to treat "__whatever=" like "&whatever="
rms264
@rms264
does sttp support server sent events?
1 reply
eugeniyk
@eugeniyk
Hello!
I didn't find any docs about compression, how sttp works with it? should custom serializers / deserializers deal with it anyhow or it's abstracted away?
11 replies
Guillaume Massé
@MasseGuillaume
Is it possible to use cachedHostConnectionPoolHttps with the Akka backend ?
eg Flow[(HttpRequest, T), (Try[HttpResponse], T), HostConnectionPool]
daymo
@daymo
Hey everyone! I have a small example project that uses sttp together with zio. I stumbled upon an error which seems to have relations to sttp's error handling. The error appears in my sample project's getContributors method. @luis3m figured out that using Throwable's getMessage with HttpError prints null. He suggested also that it would be helpful if parsing sttp's error to string includes the actual message which it does not curently. Please see https://github.com/daymo/scalainthecity
2 replies
Sebastian Voss
@sebastianvoss
Hi All, I somehow cannot get tapir to produce an http4s endpoint which does Transfer-Encoding: chunked. Is this a known issue? I was unable to find more details (also filed an issue here with some sample code: softwaremill/tapir#645). Any hint is highly appreciated.
3 replies
Saskia Gennrich
@pektinasen
I'm currently migrating a lib from sttp v1 to v2. version 1 had a parseResponseIfmethod on the request specification. I cannot find that for v2. How would I specify to parse the response even if it is a 4xx response
2 replies
Balázs Kossovics
@kosii
I was wondering, in the following case, on which threads will asJson and handleDeserializationError be executed?
    sttp
      .method(method, uri)
      .body(body)
      .headers(headers: _*)
      .readTimeout(timeout)
      .response(asJson[R])
      .mapResponse(handleDeserializationError)
      .send()
1 reply
if those operations are relatively costly because of a relatively big response payload, can that mess up the request timeouts for the rest of the requests? we are using AsyncHttpClient, and in some case the readTimeout is not respected as far as we can tell based on our monitoring
Avinder Bahra
@googley42
hi - I want to get some latency metrics from STTP into DataDog - is this possible out of the box? If not our preference would be to use zio-metrics as we are using ZIO - would we have to do something like this https://sttp.softwaremill.com/en/latest/backends/wrappers/custom.html#example-metrics-backend-wrapper? Has anyone done something similar to this?
6 replies
Avinder Bahra
@googley42
Or is the built in support for OpenTracing the way to go?
1 reply
vonchav
@voonchav_gitlab
@adamw Any chance of cutting a release for sttp-client too, now that tapir is on zio 1.0.0-RC21-2? :) (I bet ur already in the midst of doing it, haha. Thanks)
Jason Pickens
@steinybot
I am trying to use httpclient-backend-zio but how do I create a SttpClient? The one from HttpClientZioBackend is the wrong type.
1 reply
SttpClient is a Has[SttpBackend[BlockingTask, ZStream[Blocking, Throwable, Byte], NothingT]] but HttpClientZioBackend only gives a Has[SttpBackend[BlockingTask, ZStream[Blocking, Throwable, Byte], WebSocketHandler]]
Jason Pickens
@steinybot
Hmm I think that this is a regression introduced in softwaremill/sttp#603
Vitalii Supryhan
@Supryhan
image.png
Brandon Hudgeons
@bhudgeons
I'm using the ZIO backend and trying to diagnose a memory leak. threadLocalMap of io.netty.util.concurrent.FastThreadLocalThread #3009 [Thread, Stack Local] "AsyncHttpClient-5-1" tid=196 [RUNNABLE] Native ID: 16561879 14856 384 is holding on to PoolChunks containing the byte buffers of responses. Any suggestions?
Brandon Hudgeons
@bhudgeons
ah ... it looks like just using the AsyncHttpClientZioBackend().flatMap { implicit backend => as recommended in the docs creates a client every time?
10 replies
Ibrahim Moufti
@Mouftizo

Hello everyone : )

Apologies in advance if the question does not follow guidelines as I am new here. I am also new to sttp and Monix, and I am trying to learn more about these libraries. My goal is to fetch data (client-side) from a given API via HTTP GET requests -> parse JSON responses -> write this information to a database. My question pertains to the first part only. My objective is to run get requests in an asynchronous (hopefully fast) way while having a way to either avoid or handle rate limits.

Below is a snippet of what I have already tried, and seems to work for a single request:

    package com.github.me.client

    import io.circe.{Decoder, HCursor}
    import sttp.client._
    import sttp.client.circe._
    import sttp.client.asynchttpclient.monix._
    import monix.eval.Task

    object SO extends App {

      case class Bla(paging: Int)

      implicit val dataDecoder: Decoder[Bla] = (hCursor: HCursor) => {
        for {
          next_page <- hCursor.downField("foo").downArray.downField("bar").as[Int]
        } yield Bla(next_page)
      }

      val postTask = AsyncHttpClientMonixBackend().flatMap { implicit backend =>
        val r = basicRequest
          .get(uri"https://foo.bar.io/v1/baz")
          .header("accept", "application/json")
          .header("Authorization", "hushh!")
          .response(asJson[Bla])

        r.send() // How can I instead of operating on a single request, operate on multiple
          .flatMap { response =>
            Task(response.body)
          }
          .guarantee(backend.close())
      } 

      import monix.execution.Scheduler.Implicits.global

      postTask.runSyncUnsafe() match {
        case Left(error) => println(s"Error when executing request: $error")
        case Right(data) => println(data)
      }
    }

My questions:

  1. How can I operate on several GET Requests (instead of a single request) while keeping the code asynchronous and composable
  2. How can I avoid or handle hitting rate-limits imposed by the api server

On a side note, I am not particularly fixated on using Monix, and I am open to any other back-end or implementation

16 replies
sebver
@sebver

Hi! This is a very small thing, but would you be open to a PR that adds a type alias for a zio SttpBackend (the part within the Has)
https://github.com/softwaremill/sttp/blob/1e34bff7ef8bb0200d456bc8f268b3b25fdfa6ce/async-http-client-backend/zio/src/main/scala/sttp/client/asynchttpclient/zio/package.scala#L13

I find myself redefining it in several codebases to make it a bit shorter when I'm passing it around.

vonchav
@voonchav_gitlab
@adamw Should sttp-client be using sttp-model 1.1.4? It seems even the latest version sttp-client 2.2.4 is still using sttp-model 1.1.3 whereas Tapir is already using 1.1.4? :)