Skip to content

Commit

Permalink
Add some documentation for getting started
Browse files Browse the repository at this point in the history
  • Loading branch information
ascheja committed Apr 4, 2022
1 parent 394c2d1 commit fa155b8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,47 @@ xml-rpc for Kotlin/Jvm
======================

Kotlin binding for [xml-rpc](http://xmlrpc.com)


Add the dependency to your project
----------------------------------

### Client dependency using Ktor
```
implementation("org.ascheja.xmlrpc:ktor-client-xmlrpc:VERSION")
```

### Server dependency using Ktor
```
implementation("org.ascheja.xmlrpc:ktor-server-xmlrpc:VERSION")
```

### If you want to provide the transport yourself and just need the protocol
```
implementation("org.ascheja.xmlrpc:protocol:VERSION")
```

Getting started
---------------

### Client
```kotlin
val client: HttpClient = createHttpClient()
val call = MethodCall("some-method", IntegerValue(42), StringValue("some-string"))
val response = client.xmlRpc("https://some-server/rpc", call) as MethodResponseSuccess // or check for MethodResponseFault if you set the parameter `throwOnFault = false`
val firstParam = response.params.firstOrNull() as? StringValue ?: error("expected first parameter of response to be a StringValue")
```

### Server
```kotlin
embeddedServer(Netty) {
routing {
xmlRpc("/rpc") { request ->
when (request.methodName) {
"ping" -> MethodResponseSuccess(StringValue("pong"))
else -> MethodResponseFault(42, "unknown method ${request.methodName}")
}
}
}
}.start(wait = true)
```

0 comments on commit fa155b8

Please sign in to comment.