dRPC (Docta Remote Procedure Call)
Interacting with an application that uses dRPC for communication is intended to be done via service interfaces. Even though each service method can be called via HTTP endpoints.
To map service methods to HTTP endpoints, the following conventions are used:
- All endpoints have POST method (besides websocket endpoints).
- Endpoint path is formed as '{ServiceName}/{MethodName}'.
- Request and Response bodies are serialized/deserialized as JSON.
- If a method has no parameters, the request body is empty.
- if a method has parameters, they are passed as a JSON object in the request body, where keys are parameters indices (0-based).
- Response always contains 200 OK status code (if no transport or server errors occurred) and the body contains one of the following:
- SimpleResult.Success - if the method executed successfully and has no return value.
- SimpleResult.Error - if the method execution failed. The 'error' field contains error details.
- ResultData.Success - if the method executed successfully and has a return value; the 'data' field contains the return value.
- ResultData.Error - if the method execution failed. The 'error' field contains error details.
Dependency
dRPC is published on Maven Central, so you can add it as a dependency in your project using the code below.
Gradle
plugins {
id("io.github.erwinelder.drpc.shadow") version "0.4.9"
}
dependencies {
implementation("io.github.erwinelder:drpc:0.4.9")
ksp("io.github.erwinelder:drpc-processor:0.4.9")
implementation("io.github.erwinelder:drpc-client:0.4.9")
ksp("io.github.erwinelder:drpc-client-processor:0.4.9")
implementation("io.github.erwinelder:drpc-server:0.4.9")
ksp("io.github.erwinelder:drpc-server-processor:0.4.9")
}
Gradle (version catalog)
[versions]
drpc-version = "0.4.9"
[libraries]
# For both client and server APIs:
drpc = { module = "io.github.erwinelder:drpc", version.ref = "drpc-version" }
drpc-processor = { module = "io.github.erwinelder:drpc-processor", version.ref = "drpc-version" }
# For client API only:
drpc-client = { module = "io.github.erwinelder:drpc-client", version.ref = "drpc-version" }
drpc-client-processor = { module = "io.github.erwinelder:drpc-client-processor", version.ref = "drpc-version" }
# For server API only:
drpc-server = { module = "io.github.erwinelder:drpc-server", version.ref = "drpc-version" }
drpc-server-processor = { module = "io.github.erwinelder:drpc-server-processor", version.ref = "drpc-version" }
[plugins]
drpc-shadow = { id = "io.github.erwinelder.drpc.shadow", version.ref = "drpc-version" }
plugins {
alias(libs.plugins.drpc.shadow)
}
dependencies {
implementation(libs.drpc)
ksp(libs.drpc.processor)
implementation(libs.drpc.client)
ksp(libs.drpc.client.processor)
implementation(libs.drpc.server)
ksp(libs.drpc.server.processor)
}
Examples
Interface definition
Calling from the client side
Setting up the server side
Calling via HTTP
curl -X POST http:
"0": "username",
"1": "password"
}'
curl -X POST http:
"0": "token_string"
}'
curl -X POST http: