Examples by category
The sttp client repository contains a number of how-to guides. If you’re missing an example for your use-case, please let us know by reporting an issue!
Each example is fully self-contained and can be run using scala-cli (you just need to copy the content of the file, apart from scala-cli, no additional setup is required!). Hopefully this will make experimenting with sttp client as frictionless as possible!
Examples are tagged with the stack being used (direct-style, cats-effect, ZIO, Future) and backend implementation
Hello, World!
Dynamic URI components HttpClient Direct
POST form data HttpClient Direct
POST multipart form HttpClient Direct
Post JSON data HttpClient Monix
Upload file HttpClient Direct
Backend wrapper
A backend which adds a header to all outgoing requests HttpClient Synchronous
Integrate with resilience4j to implement circuit-breaking HttpClient cats-effect
Integrate with resilience4j to implement rate-limiting HttpClient Future
Report metrics to a cloud service Pekko Future
Simple retrying backend wrapper HttpClient Synchronous
Use the caching backend wrapper with Redis HttpClient Synchronous
JSON
Receive & parse JSON using ZIO Json HttpClient ZIO
Receive & parse JSON using circe HttpClient cats-effect
Receive & parse JSON using circe HttpClient Monix
Receive & parse JSON using json4s Pekko Future
Receive & parse JSON using jsoniter HttpClient Direct
Logging
Add a logging backend wrapper, which uses slf4j HttpClient Direct
Other
Command output streaming with os-lib support HttpClient Direct
Download file with os-lib support HttpClient Direct
Download file with os-lib support HttpClient Direct
Handle the body by both parsing it to JSON and returning the raw string HttpClient Direct
Resilience
Rate limit sending requests using Ox HttpClient Direct
Retry sending a request using Ox HttpClient Direct
Retry sending a request using ZIO’s retries HttpClient ZIO
Streaming
Stream request & response bodies using ZIO-Streams HttpClient ZIO
Stream request & response bodies using fs2 HttpClient cats-effect
Testing
WebSocket
Connect to & interact with a WebSocket Pekko Future
Connect to & interact with a WebSocket HttpClient ZIO
Connect to & interact with a WebSocket HttpClient Direct
Connect to & interact with a WebSocket HttpClient Monix
Connect to & interact with a WebSocket, using Ox channels for streaming HttpClient Direct
Connect to & interact with a WebSocket, using fs2 streaming HttpClient cats-effect