Skip to content

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 ​

ComponentDescription
HTTP ClientSync and async HTTP clients
REST ServerCross-platform HTTP server (built-in / Netty / Node.js) with routing
RouterType-safe route definitions
RPCType-safe remote calls over HTTP, with client code generation
Server-Sent EventsOne-way server→client streaming
WebSocket ClientCross-platform bidirectional WebSocket client
OpenAPIOpenAPI 3.0 documents from @Endpoint routes
HTTP Retry StrategiesAutomatic 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 ​

TypeMethodUse Case
SyncnewSyncClientSimple blocking requests
AsyncnewAsyncClientNon-blocking with Rx

Package ​

scala
import wvlet.uni.http.*

Released under the Apache 2.0 License.