HTTP & RPC
Uni provides a cross-platform HTTP client and server, with automatic retry, streaming support, and reactive integration. The client runs on the JVM (java.net.http), Scala.js (Fetch / Node.js), and Scala Native (libcurl). The server is built into uni on the JVM (JDK 24+) and Scala Native, uses Node.js http on Scala.js, and can run on Netty on the JVM with the optional uni-netty module.
Overview
| Component | Description |
|---|---|
| HTTP Client | Sync and async HTTP clients |
| REST Server | Cross-platform HTTP server (built-in / Netty / Node.js) with routing |
| Router | Type-safe route definitions |
| RPC | Type-safe remote calls over HTTP, with client code generation |
| Server-Sent Events | One-way server→client streaming |
| WebSocket Client | Cross-platform bidirectional WebSocket client |
| OpenAPI | OpenAPI 3.0 documents from @Endpoint routes |
| HTTP Retry Strategies | Automatic retry for transient failures |
| MCP Server (stdio) | A Scala trait as an MCP server that AI agents call as tools |
| Desktop Apps (Electron) | Typed RPC between an Electron main process and a Scala.js renderer |
Quick Start
scala
import wvlet.uni.http.{Http, Request}
// Create a client
val client = Http.client.newSyncClient
// Make a GET request
val response = client.send(Request.get("https://api.example.com/users"))
println(response.contentAsString)
// Close the client
client.close()Async Client with Rx
scala
import wvlet.uni.http.Http
val asyncClient = Http.client.newAsyncClient
asyncClient
.send(Request.get("https://api.example.com/data"))
.map(_.contentAsString)
.subscribe { content =>
println(s"Received: ${content}")
}Key Features
- Cross-Platform - Works on JVM, Scala.js, and Scala Native
- Automatic Retry - Built-in retry with exponential backoff
- Streaming - Stream response bodies as byte chunks
- Reactive - Async client returns
Rx[HttpResponse] - Configurable - Timeouts, retries, headers
Client Types
| Type | Method | Use Case |
|---|---|---|
| Sync | newSyncClient | Simple blocking requests |
| Async | newAsyncClient | Non-blocking with Rx |
Package
scala
import wvlet.uni.http.*