by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 15:44
    ghostbuster91 edited #620
  • 15:43
    ghostbuster91 edited #620
  • 15:35
    ghostbuster91 edited #620
  • 15:35
    ghostbuster91 edited #620
  • 15:34
    ghostbuster91 synchronize #620
  • 15:34

    ghostbuster91 on typed-errors

    Fix compilation issue (compare)

  • 15:29
    ghostbuster91 ready_for_review #620
  • 15:26
    ghostbuster91 synchronize #620
  • 15:26

    ghostbuster91 on typed-errors

    Reuse ErrorResponseAs (compare)

  • 15:26
    ghostbuster91 synchronize #620
  • 15:26

    ghostbuster91 on typed-errors

    Extract new type (compare)

  • 15:21
    ghostbuster91 synchronize #620
  • 15:21

    ghostbuster91 on typed-errors

    Return HttpError by default (compare)

  • 14:36
    ghostbuster91 synchronize #620
  • 14:36

    ghostbuster91 on typed-errors

    Add generic asTypedError and as… Update docs (compare)

  • 12:59
    ghostbuster91 synchronize #620
  • 12:59

    ghostbuster91 on typed-errors

    Next iteration (compare)

  • 09:56
    magdzikk synchronize #602
  • 09:56

    magdzikk on convert-docs-to-mdoc

    Use zio.App explicitly for clar… Fix CookieWithMeta class in docs (compare)

  • Jul 02 12:01
    ghostbuster91 opened #623
Mark de Jong
@Fristi
Hi,
I'm creating a PR, but while importing the project in IntelliJ it fails when I add new module
failed
dump project structure from sbt
stack trace is suppressed; run 'last zioTelemetryOpenTracingBackend / coursierResolutions' for the full output
stack trace is suppressed; run 'last zioTelemetryOpenTracingBackend / ssExtractDependencies' for the full output
(zioTelemetryOpenTracingBackend / coursierResolutions) coursier.ResolutionException: Encountered 2 error(s) in dependency resolution:
com.softwaremill.sttp.client:zio_2.12:2.0.10-SNAPSHOT:
not found:
/Users/markdejong/.ivy2/local/com.softwaremill.sttp.client/zio_2.12/2.0.10-SNAPSHOT/ivys/ivy.xml
https://repo1.maven.org/maven2/com/softwaremill/sttp/client/zio_2.12/2.0.10-SNAPSHOT/zio_2.12-2.0.10-SNAPSHOT.pom
https://oss.sonatype.org/content/repositories/releases/com/softwaremill/sttp/client/zio_2.12/2.0.10-SNAPSHOT/zio_2.12-2.0.10-SNAPSHOT.pom
https://oss.sonatype.org/content/repositories/snapshots/com/softwaremill/sttp/client/zio_2.12/2.0.10-SNAPSHOT/zio_2.12-2.0.10-SNAPSHOT.pom
https://repository.jboss.org/nexus/content/repositories/com/softwaremill/sttp/client/zio_2.12/2.0.10-SNAPSHOT/zio_2.12-2.0.10-SNAPSHOT.pom
https://dl.bintray.com/scalaz/releases/com/softwaremill/sttp/client/zio_2.12/2.0.10-SNAPSHOT/zio_2.12-2.0.10-SNAPSHOT.pom
https://dl.bintray.com/non/maven/com/softwaremill/sttp/client/zio_2.12/2.0.10-SNAPSHOT/zio_2.12-2.0.10-SNAPSHOT.pom
com.softwaremill.sttp.client:core_2.12:2.0.10-SNAPSHOT:
/Users/markdejong/.ivy2/local/com.softwaremill.sttp.client/core_2.12/2.0.10-SNAPSHOT/ivys/ivy.xml
https://repo1.maven.org/maven2/com/softwaremill/sttp/client/core_2.12/2.0.10-SNAPSHOT/core_2.12-2.0.10-SNAPSHOT.pom
https://oss.sonatype.org/content/repositories/releases/com/softwaremill/sttp/client/core_2.12/2.0.10-SNAPSHOT/core_2.12-2.0.10-SNAPSHOT.pom
https://oss.sonatype.org/content/repositories/snapshots/com/softwaremill/sttp/client/core_2.12/2.0.10-SNAPSHOT/core_2.12-2.0.10-SNAPSHOT.pom
https://repository.jboss.org/nexus/content/repositories/com/softwaremill/sttp/client/core_2.12/2.0.10-SNAPSHOT/core_2.12-2.0.10-SNAPSHOT.pom
https://dl.bintray.com/scalaz/releases/com/softwaremill/sttp/client/core_2.12/2.0.10-SNAPSHOT/core_2.12-2.0.10-SNAPSHOT.pom
https://dl.bintray.com/non/maven/com/softwaremill/sttp/client/core_2.12/2.0.10-SNAPSHOT/core_2.12-2.0.10-SNAPSHOT.pom
(zioTelemetryOpenTracingBackend / ssExtractDependencies) coursier.ResolutionException: Encountered 2 error(s) in dependency resolution:
Total time: 12 s, completed Apr 20, 2020 2:47:30 PM
14 replies
nyudigitaldesignlab
@nyudigitaldesignlab

Hi all,
I'm trying the following using sttp.circe

  def query[T: Query : Decoder](patient: Patient): Either[String, List[T]] = {
    val patientQueryData = implicitly[Query[T]]

    val request = basicRequest
      .auth.bearer(authToken)
      .get(uri"https://$baseURL/${patient.id}/${patientQueryData.path}/${patientQueryData.params(patient)}")

    implicit val backend: SttpBackend[Identity, Nothing, NothingT] = HttpURLConnectionBackend()

    val response = request.send()

    response(asJson[List[T]])
  }

but it fails with
Error:(25, 13) sttp.client.Identity[sttp.client.Response[Either[String,String]]] does not take parameters response(asJson[List[T]])
I suspect this might be related to the Decoder for T not being properly inferred/in scope. Using io.circe.generic.semiauto._ would not save me any work at all as my classes are deeply nested and I'd have to define a fair amount of decoders so parsing manually might be more efficient (LOC-wise)
But I could be totally wrong and my issue is something else?
Any hints will be much appreciated

ybasket
@ybasket
@nyudigitaldesignlab How to decode is part of the request definition, so call the response(asJson[List[T]]) there, for example just after .get:
  def query[T: Query : Decoder](patient: Patient): Either[String, List[T]] = {
    val patientQueryData = implicitly[Query[T]]

    val request = basicRequest
      .auth.bearer(authToken)
     .get(uri"https://$baseURL/${patient.id}/${patientQueryData.path}/${patientQueryData.params(patient)}“)
    .response(asJson[List[T]])

    implicit val backend: SttpBackend[Identity, Nothing, NothingT] = HttpURLConnectionBackend()

    val response = request.send()
// … handle response errors here
  }
Btw, sttp backends are something to be reused, so don’t create one for evry HTTP call, but define one at a larger scope.
Boris V.Kuznetsov
@tampler
Hi guys! I need to support JSON in RequestT. I added Circe decoder in code, but can't add Circe to the core project. Could you pls advice how to do that? Here's my PR: #508
Boris V.Kuznetsov
@tampler
Okay, I seems to have found a better solution. I actually need a basicToken authorization. Will make a MR now for that
nyudigitaldesignlab
@nyudigitaldesignlab
@ybasket Thanks! That makes total sense now in hindsight.
nyudigitaldesignlab
@nyudigitaldesignlab

Hi all, me again with the same example as before.
Finally got time to test it and I'm getting this error error: This is a partial request, the method & url are not specified. Use .get(...), .post(...) etc. to obtain a non-partial request.
Which is weird because the the method and url are definitely specified
I ended up replacing the uri with a plain representation (no string interpolation) but that's not the issue either.
Thoughts?

@nyudigitaldesignlab How to decode is part of the request definition, so call the response(asJson[List[T]]) there, for example just after .get:

  def query[T: Query : Decoder](patient: Patient): Either[String, List[T]] = {
    val patientQueryData = implicitly[Query[T]]

    val request = basicRequest
      .auth.bearer(authToken)
     .get(uri"https://$baseURL/${patient.id}/${patientQueryData.path}/${patientQueryData.params(patient)}“)
    .response(asJson[List[T]])

    implicit val backend: SttpBackend[Identity, Nothing, NothingT] = HttpURLConnectionBackend()

    val response = request.send()
// … handle response errors here
  }
4 replies
truongio
@truongio

Hi, I'm wondering how do I specify a custom SSLContext when I create an AsyncHttpClientZioBackend.

Edit: Think I found it.

AsyncHttpClientZioBackend.usingConfigBuilder(
      _.setSslContext()
    )
Christian Kaps
@akkie

I think there is a regression in the current sttp versions. The following test throws an ClassCastException.


import cats.implicits._
import sttp.client._
import cats.effect.{ Async, ContextShift, IO }
import org.specs2.mutable.Specification
import sttp.client.{ Response, StringBody }
import sttp.client.asynchttpclient.cats.AsyncHttpClientCatsBackend
import sttp.model.{ MediaType, StatusCode }

import scala.concurrent.ExecutionContext
import scala.io.Codec

class SttpTestSpec extends Specification {

  implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContext.Implicits.global)
  class RequestHandler[F[_]: Async] {
    def request()(implicit sttpBackend: SttpBackend[F, Nothing, Nothing]): F[String] = {
      basicRequest.get(uri"http://example.org/a/b/c").send().map(_.body match {
        case Left(error)   => error
        case Right(result) => result
      })
    }
  }

  "The `test` method" should {
    "work" in {
      implicit val sttpBackend = AsyncHttpClientCatsBackend.stub[IO]
        .whenAnyRequest
        .thenRespond(Response(
          StringBody("{}", Codec.UTF8.charSet.name(), Some(MediaType.ApplicationJson)),
          StatusCode.BadRequest
        ))

      val handler = new RequestHandler[IO]

      handler.request()(sttpBackend).unsafeRunSync() must be equalTo "{}"
    }
  }
}

This is the exception:

java.lang.ClassCastException: sttp.client.StringBody cannot be cast to scala.util.Either
java.lang.ClassCastException: sttp.client.StringBody cannot be cast to scala.util.Either
    at silhouette.provider.oauth2.SttpTestSpec$RequestHandler.$anonfun$request$1(SttpTestSpec.scala:39)
    at scala.Function1.$anonfun$andThen$1(Function1.scala:85)
    at cats.effect.IO$Map.apply(IO.scala:1504)
    at cats.effect.IO$Map.apply(IO.scala:1502)
    at cats.effect.internals.IORunLoop$.liftedTree3$1(IORunLoop.scala:238)
    at cats.effect.internals.IORunLoop$.step(IORunLoop.scala:238)
    at cats.effect.IO.unsafeRunTimed(IO.scala:321)
    at cats.effect.IO.unsafeRunSync(IO.scala:240)
    at silhouette.provider.oauth2.SttpTestSpec.$anonfun$new$4(SttpTestSpec.scala:57)
    at org.specs2.matcher.Expectable.value$lzycompute(Expectable.scala:21)
    at org.specs2.matcher.Expectable.value(Expectable.scala:21)
    at org.specs2.matcher.EqualityMatcher.apply(EqualityMatcher.scala:25)
    at org.specs2.matcher.Expectable.applyMatcher(Expectable.scala:51)
    at org.specs2.matcher.MustThrownExpectationsCreation$$anon$4.applyMatcher(MustExpectations.scala:67)
    at org.specs2.matcher.MatchSuccess.apply(MatchResult.scala:124)
    at org.specs2.matcher.NeutralMatch.apply(MatchResult.scala:207)
    at org.specs2.matcher.AnyBeHaveMatchers$AnyBeHaveMatchers.equalTo(AnyMatchers.scala:198)
    at silhouette.provider.oauth2.SttpTestSpec.$anonfun$new$2(SttpTestSpec.scala:57)
    at org.specs2.matcher.MatchResult$$anon$12.$anonfun$asResult$1(MatchResult.scala:344)
    at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
    at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
    at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
    at org.specs2.execute.Result$$anon$4.asResult(Result.scala:246)
    at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
    at org.specs2.matcher.MatchResult$$anon$12.asResult(MatchResult.scala:344)
    at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
    at org.specs2.specification.core.AsExecution$$anon$1.$anonfun$execute$1(AsExecution.scala:17)
    at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
    at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
    at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
    at org.specs2.execute.Result$$anon$4.asResult(Result.scala:246)
    at org.specs2.execute.AsResult$.apply(AsResult.scala:32)
    at org.specs2.execute.AsResult$.$anonfun$safely$1(AsResult.scala:40)
    at org.specs2.execute.ResultExecution.execute(ResultExecution.scala:22)
    at org.specs2.execute.ResultExecution.execute$(ResultExecution.scala:21)
    at org.specs2.execute.ResultExecution$.execute(ResultExecution.scala:123)
    at org.
3 replies
Milan van der Meer
@milanvdm

Hi all, Im adding some auto-instrumentation using the ElasticAPM and its java-agent.
It is able to trace thread switches fine and also the actual request of sttp with the underlying AsyncJavaClient.

But for some reason it loses the trace-contract during the logging logic:
basicRequest.get(uri"https://postman-echo.com/get?foo2=bar2").send().void.flatTap(_ => Future(logger.info("test"))

So the request is correctly traced, but the log not.
Meaning that between the execution of the http request future and the log, for some reason, there is a thread-switch outside if the traced Runnable. The logging works fine in the same code when using a jdbc call for example so it is specific to sttp.
Does someone have any idea why that could happen in the sttp/AsyncJavaClient?

2 replies
Anirudh Vyas
@AnirudhVyas
 def exec(input: String): Task[Either[WebSocketEvent.Close, String]] =
    AsyncHttpClientMonixBackend()
      .flatMap { implicit backend =>
        // using a test websocket endpoint
        implicit val s: Scheduler = monix.execution.Scheduler.global
        val response: Task[WebSocketResponse[WebSocket[Task]]] = basicRequest
          .get(uri"ws://something.org")
          .openWebsocket(MonixWebSocketHandler())

        // the "response" is an effect once which will store the websocket instance,
        // once the websocket is established
        response.flatMap { r =>
          val ws: WebSocket[Task] = r.result
          Task
            .sleep(1.second)
            .flatMap(_ => ws.send(WebSocketFrame.text(input)))
            .flatMap(_ => ws.receiveText())
        }
      }

I am attempting to compile above (very new to sttp, cats etc.) however I am getting a compilation error :

info] Compiling 5 Scala sources to /Users/anirudh.vyas/scala/divergent_commits/backout/qtf-scala/target/scala-2.13/classes ...
[error] /Users/anirudh.vyas/scala/divergent_commits/backout/qtf-scala/src/main/scala/qtf/ws/WSIO.scala:20:25: polymorphic expression cannot be instantiated to expected type;
[error]  found   : [F[_]]F[sttp.client.ws.WebSocketResponse[Object]]
[error]  required: monix.eval.Task[sttp.client.ws.WebSocketResponse[sttp.client.ws.WebSocket[monix.eval.Task]]]
[error]           .openWebsocket(MonixWebSocketHandler())

Unsure what am I doing wrong ...

3 replies
Thijs
@ThijsBroersen
This message was deleted
7 replies
Laszlo Konya
@lkonya
Hi there!
I would like to create a wrapper backend. Is there a way to access the request body? (I would need a string representation for creating a signature)
4 replies
Arun Gopalpuri
@arun0009
Is there a way to log all request/response in sttp?
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?
2 replies
Guillaume Massé
@MasseGuillaume
Is it possible to use cachedHostConnectionPoolHttps with the Akka backend ?
eg Flow[(HttpRequest, T), (Try[HttpResponse], T), HostConnectionPool]