Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Warski adamw

View GitHub Profile
View tapir.scala
trait TapirHandler extends RequestStreamHandler {
def endpoints: List[ServerEndpoint[_, _, _, Any, Identity]]
override def handleRequest(input: InputStream, output: OutputStream,
context: Context): Unit = {
val json = new String(input.readAllBytes(), UTF_8)
val writer = new BufferedWriter(new OutputStreamWriter(output, UTF_8))
writer.write(handleRequest(json))
writer.flush()
}
View example.yaml
asyncapi: 2.0.0
info:
title: JSON echo
version: '1.0'
servers:
dev:
url: localhost:8080
protocol: ws
channels:
/ping:
View test.scala
import monix.reactive.Observable
import sttp.capabilities.monix.MonixStreams
object Test extends App {
import sttp.client3._
import monix.execution.Scheduler.Implicits.global
val b = AsyncHttpClientMonixBackend().runSyncUnsafe()
basicRequest.post(uri"http://198.51.100.0").streamBody(MonixStreams)(Observable.empty).send(b).runSyncUnsafe()
View endpointwiden.scala
package sttp.tapir.server.http4s.ztapir
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers
import sttp.monad.MonadError
import zio.{Has, RIO, Runtime, ZIO}
import zio.interop.catz._
import zio.interop.catz.implicits._
import sttp.tapir._
import sttp.tapir.server.ServerEndpoint
View ws.scala
package sttp.client3.examples
import monix.eval.Task
import sttp.capabilities.WebSockets
import sttp.capabilities.monix.MonixStreams
import sttp.client3._
import sttp.client3.asynchttpclient.monix.AsyncHttpClientMonixBackend
import sttp.client3.testing.SttpBackendStub
import sttp.model.StatusCode
import sttp.ws.{WebSocket, WebSocketFrame}
View json.scala
package sttp.client3.examples
import io.circe.generic.auto._
import sttp.client3._
import sttp.client3.asynchttpclient.monix.AsyncHttpClientMonixBackend
import sttp.client3.circe._
object GetAndParseJsonGetRightMonixCirce extends App {
import monix.execution.Scheduler.Implicits.global
View raw.scala
package sttp.client3.examples
import io.circe
import io.circe.generic.auto._
import sttp.client3._
import sttp.client3.circe._
object GetRawRequestBodySynchronous extends App {
case class HttpBinResponse(origin: String, headers: Map[String, String])
View streams.scala
package sttp.client3.examples
import sttp.capabilities.zio.ZioStreams
import sttp.client3._
import sttp.client3.asynchttpclient.zio.{AsyncHttpClientZioBackend, SttpClient}
import zio._
import zio.console._
import zio.stream._
object StreamZio extends App {
View ws.scala
package sttp.client3.examples
import cats.effect.{ContextShift, IO}
import fs2._
import sttp.capabilities.fs2.Fs2Streams
import sttp.client3._
import sttp.client3.asynchttpclient.fs2.AsyncHttpClientFs2Backend
import sttp.ws.WebSocketFrame
object WebSocketStreamFs2 extends App {
View ws.scala
package sttp.client3.examples
import sttp.client3._
import sttp.client3.akkahttp.AkkaHttpBackend
import sttp.ws.WebSocket
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
object WebSocketAkka extends App {