Skip to content

Commit

Permalink
Migrate examples & docs to Scala 3 (#2375)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamw authored Dec 19, 2024
1 parent 76c3a57 commit 15d15b1
Show file tree
Hide file tree
Showing 56 changed files with 472 additions and 563 deletions.
167 changes: 76 additions & 91 deletions build.sbt

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/backends/akka.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Note that you'll also need an explicit dependency on akka-streams, as akka-http

Next you'll need to add create the backend instance:

```scala mdoc:compile-only
```scala
import sttp.client4.akkahttp._
val backend = AkkaHttpBackend()
```

or, if you'd like to use an existing actor system:

```scala mdoc:compile-only
```scala
import sttp.client4.akkahttp._
import akka.actor.ActorSystem

Expand All @@ -35,7 +35,7 @@ This backend supports sending and receiving [akka-streams](http://doc.akka.io/do

To set the request body as a stream:

```scala mdoc:compile-only
```scala
import sttp.capabilities.akka.AkkaStreams
import sttp.client4._

Expand All @@ -51,7 +51,7 @@ basicRequest

To receive the response body as a stream:

```scala mdoc:compile-only
```scala
import scala.concurrent.Future
import sttp.capabilities.akka.AkkaStreams
import sttp.client4._
Expand Down Expand Up @@ -79,7 +79,7 @@ That way, you can "mock" a server that the backend will talk to, without startin

If your application provides a client library for its dependants to use, this is a great way to ensure that the client actually matches the routes exposed by your application:

```scala mdoc:compile-only
```scala
import sttp.client4.akkahttp._
import akka.http.scaladsl.server.Route
import akka.actor.ActorSystem
Expand All @@ -101,7 +101,7 @@ Non-standard behavior:

Received data streams can be parsed to a stream of server-sent events (SSE):

```scala mdoc:compile-only
```scala
import scala.concurrent.Future

import akka.stream.scaladsl.Source
Expand Down
10 changes: 5 additions & 5 deletions docs/backends/fs2.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ or, if you'd like to instantiate the [WebClient](https://armeria.dev/docs/client
import cats.effect.IO
import cats.effect.std.Dispatcher
import com.linecorp.armeria.client.WebClient
import com.linecorp.armeria.client.circuitbreaker._
import com.linecorp.armeria.client.circuitbreaker.*
import sttp.client4.armeria.fs2.ArmeriaFs2Backend

val dispatcher: Dispatcher[IO] = ???
Expand Down Expand Up @@ -135,7 +135,7 @@ Requests can be sent with a streaming body like this:
import cats.effect.IO
import fs2.Stream
import sttp.capabilities.fs2.Fs2Streams
import sttp.client4._
import sttp.client4.*
import sttp.client4.httpclient.fs2.HttpClientFs2Backend

val effect = HttpClientFs2Backend.resource[IO]().use { backend =>
Expand All @@ -155,7 +155,7 @@ Responses can also be streamed:
import cats.effect.IO
import fs2.Stream
import sttp.capabilities.fs2.Fs2Streams
import sttp.client4._
import sttp.client4.*
import sttp.client4.httpclient.fs2.HttpClientFs2Backend
import scala.concurrent.duration.Duration

Expand All @@ -181,9 +181,9 @@ The fs2 backends support both regular and streaming [websockets](../websockets.m
Received data streams can be parsed to a stream of server-sent events (SSE):

```scala mdoc:compile-only
import cats.effect._
import cats.effect.*
import fs2.Stream
import sttp.client4._
import sttp.client4.*
import sttp.capabilities.fs2.Fs2Streams
import sttp.client4.impl.fs2.Fs2ServerSentEvents
import sttp.model.sse.ServerSentEvent
Expand Down
21 changes: 11 additions & 10 deletions docs/backends/future.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

There are several backend implementations which are `scala.concurrent.Future`-based. These backends are **asynchronous**, sending a request is a non-blocking operation and results in a response wrapped in a `Future`.

Apart from the ones described below, also the [Akka](akka.md) backend is `Future`-based.
Apart from the ones described below, also the [Pekko](pekko.md) & [Akka](akka.md) backends are `Future`-based.

```eval_rst
===================================== ================================================ ==========================
Class Supported stream type Websocket support
===================================== ================================================ ==========================
``HttpClientFutureBackend`` n/a yes (regular)
``AkkaHttpBackend`` ``akka.stream.scaladsl.Source[ByteString, Any]`` yes (regular & streaming)
``OkHttpFutureBackend`` n/a yes (regular)
``ArmeriaFutureBackend`` n/a n/a
===================================== ================================================ ==========================
===================================== ================================================= ==========================
Class Supported stream type Websocket support
===================================== ================================================= ==========================
``HttpClientFutureBackend`` n/a yes (regular)
``PekkoHttpBackend`` ``pekko.stream.scaladsl.Source[ByteString, Any]`` yes (regular & streaming)
``AkkaHttpBackend`` ``akka.stream.scaladsl.Source[ByteString, Any]`` yes (regular & streaming)
``OkHttpFutureBackend`` n/a yes (regular)
``ArmeriaFutureBackend`` n/a n/a
===================================== ================================================= ==========================
```

## Using HttpClient
Expand Down Expand Up @@ -111,7 +112,7 @@ ArmeriaFutureBackend.usingDefaultClient()
or, if you'd like to instantiate the [WebClient](https://armeria.dev/docs/client-http) yourself::

```scala mdoc:compile-only
import com.linecorp.armeria.client.circuitbreaker._
import com.linecorp.armeria.client.circuitbreaker.*
import com.linecorp.armeria.client.WebClient

// Fluently build Armeria WebClient with built-in decorators
Expand Down
6 changes: 3 additions & 3 deletions docs/backends/http4s.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ This backend is based on [http4s](https://http4s.org) (client) and is **asynchro
The backend can be created in a couple of ways, e.g.:

```scala mdoc:compile-only
import cats.effect._
import cats.effect.*
import sttp.capabilities.fs2.Fs2Streams
import sttp.client4._
import sttp.client4.http4s._
import sttp.client4.*
import sttp.client4.http4s.*

// the "org.http4s" %% "http4s-ember-client" % http4sVersion dependency needs to be explicitly added
Http4sBackend.usingDefaultEmberClientBuilder[IO](): Resource[IO, StreamBackend[IO, Fs2Streams[IO]]]
Expand Down
6 changes: 3 additions & 3 deletions docs/backends/javascript/fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ To use, add the following dependency to your project:
An example of streaming a response:

```scala
import sttp.client4._
import sttp.client4.impl.monix._
import sttp.client4.*
import sttp.client4.impl.monix.*

import java.nio.ByteBuffer
import monix.eval.Task
Expand Down Expand Up @@ -170,7 +170,7 @@ import monix.eval.Task
import sttp.capabilities.monix.MonixStreams
import sttp.client4.impl.monix.MonixServerSentEvents
import sttp.model.sse.ServerSentEvent
import sttp.client4._
import sttp.client4.*

def processEvents(source: Observable[ServerSentEvent]): Task[Unit] = ???

Expand Down
8 changes: 4 additions & 4 deletions docs/backends/monix.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ArmeriaMonixBackend.usingDefaultClient()
or, if you'd like to instantiate the [WebClient](https://armeria.dev/docs/client-http) yourself:

```scala
import com.linecorp.armeria.client.circuitbreaker._
import com.linecorp.armeria.client.circuitbreaker.*
import com.linecorp.armeria.client.WebClient

// Fluently build Armeria WebClient with built-in decorators
Expand All @@ -124,7 +124,7 @@ The Monix backends support streaming. The streams capability is represented as `

```scala
import sttp.capabilities.monix.MonixStreams
import sttp.client4._
import sttp.client4.*
import sttp.client4.httpclient.monix.HttpClientMonixBackend

import monix.reactive.Observable
Expand All @@ -143,7 +143,7 @@ And receive responses as an observable stream:

```scala
import sttp.capabilities.monix.MonixStreams
import sttp.client4._
import sttp.client4.*
import sttp.client4.httpclient.monix.HttpClientMonixBackend

import monix.eval.Task
Expand Down Expand Up @@ -176,7 +176,7 @@ import monix.eval.Task
import sttp.capabilities.monix.MonixStreams
import sttp.client4.impl.monix.MonixServerSentEvents
import sttp.model.sse.ServerSentEvent
import sttp.client4._
import sttp.client4.*

def processEvents(source: Observable[ServerSentEvent]): Task[Unit] = ???

Expand Down
10 changes: 5 additions & 5 deletions docs/backends/pekko.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ Note that you'll also need an explicit dependency on pekko-streams, as pekko-htt
Next you'll need to add create the backend instance:

```scala mdoc:compile-only
import sttp.client4.pekkohttp._
import sttp.client4.pekkohttp.*
val backend = PekkoHttpBackend()
```

or, if you'd like to use an existing actor system:

```scala mdoc:compile-only
import sttp.client4.pekkohttp._
import sttp.client4.pekkohttp.*
import org.apache.pekko.actor.ActorSystem

val actorSystem: ActorSystem = ???
Expand All @@ -37,7 +37,7 @@ To set the request body as a stream:

```scala mdoc:compile-only
import sttp.capabilities.pekko.PekkoStreams
import sttp.client4._
import sttp.client4.*

import org.apache.pekko
import pekko.stream.scaladsl.Source
Expand All @@ -55,7 +55,7 @@ To receive the response body as a stream:
```scala mdoc:compile-only
import scala.concurrent.Future
import sttp.capabilities.pekko.PekkoStreams
import sttp.client4._
import sttp.client4.*
import sttp.client4.pekkohttp.PekkoHttpBackend

import org.apache.pekko
Expand All @@ -82,7 +82,7 @@ That way, you can "mock" a server that the backend will talk to, without startin
If your application provides a client library for its dependants to use, this is a great way to ensure that the client actually matches the routes exposed by your application:

```scala mdoc:compile-only
import sttp.client4.pekkohttp._
import sttp.client4.pekkohttp.*
import org.apache.pekko
import pekko.http.scaladsl.server.Route
import pekko.actor.ActorSystem
Expand Down
6 changes: 3 additions & 3 deletions docs/backends/scalaz.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ To use, add the following dependency to your project:

add imports:

```scala mdoc:silent
```scala
import sttp.client4.armeria.scalaz.ArmeriaScalazBackend
```

create client:

```scala mdoc:compile-only
```scala
val backend = ArmeriaScalazBackend()

// You can use the default client which reuses the connection pool of ClientFactory.ofDefault()
Expand All @@ -28,7 +28,7 @@ ArmeriaScalazBackend.usingDefaultClient()

or, if you'd like to instantiate the [WebClient](https://armeria.dev/docs/client-http) yourself:

```scala mdoc:compile-only
```scala
import com.linecorp.armeria.client.circuitbreaker._
import com.linecorp.armeria.client.WebClient

Expand Down
2 changes: 1 addition & 1 deletion docs/backends/synchronous.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ or, if you'd like to instantiate the OkHttpClient yourself:

```scala mdoc:compile-only
import sttp.client4.okhttp.OkHttpSyncBackend
import okhttp3._
import okhttp3.*

val okHttpClient: OkHttpClient = ???
val backend = OkHttpSyncBackend.usingClient(okHttpClient)
Expand Down
Loading

0 comments on commit 15d15b1

Please sign in to comment.