Automorph is a Scala RPC client and server library for invoking and exposing remote APIs in a few lines of code.
- Seamless - Generate optimized RPC client or server bindings from existing public API methods at compile time.
- Flexible - Customize data serialization, remote API function names, RPC protocol errors and authentication.
- Modular - Choose plugins for RPC protocol, effect handling, transport protocol and message format.
- Permissive - Consume or create dynamic message payload and access or modify transport protocol metadata.
- Discoverable - Utilize discovery functions providing OpenRPC 1.3+ and OpenAPI 3.1+ schemas for exposed APIs.
- Compatible - Use with Scala 3.3+ or 2.13+ on JRE 11+ and easily integrate with various popular libraries.
- RPC protocols - JSON-RPC, Web-RPC.
- Transport protocols - HTTP, WebSocket, AMQP.
- Effect handling - Synchronous, Asynchronous, Monadic.
// Define a remote API
trait Api:
def hello(n: Int): Future[String]
// Create server implementation of the remote API
val service = new Api:
def hello(n: Int): Future[String] = Future(s"Hello world $n")
// Expose a server API implementation to be called remotely
val apiServer = server.bind(service)
// Create a type-safe local proxy for the remote API from an API trait
val remoteApi = client.bind[Api]
// Call the remote API function via the local proxy
remoteApi.hello(1)
// Call the remote API function dynamically without using the API trait
client.call[String]("hello")("n" -> 1)
Note: Mundane parts of the code are omitted and can be found in the full example.