Pluskode Client SDK for Android - Kotlin client with HTTP, WebSocket, SSE, gRPC, MQTT, and Binary Stream support
npm install @pluskode/client-androidkotlin
// build.gradle.kts
dependencies {
implementation("com.pluskode:client:0.1.0")
}
`
$3
`groovy
dependencies {
implementation 'com.pluskode:client:0.1.0'
}
`
Usage
$3
`kotlin
import com.pluskode.client.*
val client = PluskodeClient.create(
PluskodeClientOptions(
baseURL = "http://localhost:3000",
timeout = 30_000,
retries = 3
)
)
// Set authentication
client.setAuth("Bearer", "your-jwt-token")
`
$3
`kotlin
// GET request
val users = client.get>>("/api/users")
// POST request
val newUser = client.post
`
$3
`kotlin
// Subscribe to channel
val unsubscribe = client.subscribe("chat/room1") { data ->
println("Message: $data")
}
// Send message
client.send("chat/room1", mapOf("text" to "Hello!"))
// Unsubscribe
unsubscribe()
`
$3
`kotlin
val unsubscribe = client.subscribeSSE("/events/stream") { event ->
println("Event: ${event.event}, Data: ${event.data}")
}
// Close
unsubscribe()
`
$3
`kotlin
val user = client.rpc`
$3
`kotlin
// Subscribe
val unsubscribe = client.subscribeMQTT(
topic = "sensors/temperature",
callback = { topic, message, qos ->
println("$topic: $message (QoS: $qos)")
},
options = MQTTOptions(qos = 1)
)
// Publish
client.publishMQTT(
topic = "sensors/temperature",
message = "25.5",
options = MQTTOptions(qos = 1, retain = false)
)
`
$3
`kotlin
val close = client.connectBinary("/custom-protocol") { data ->
println("Received ${data.size} bytes")
}
// Close
close()
`
$3
`kotlin
// All methods are suspend functions
lifecycleScope.launch {
try {
val users = client.get>("/api/users")
// Update UI
} catch (e: Exception) {
// Handle error
}
}
`
$3
`kotlin
// Cleanup all connections
client.destroy()
`
Project Structure
`
client/android/
āāā src/
ā āāā main/
ā ā āāā kotlin/
ā ā ā āāā com/pluskode/client/
ā ā ā āāā PluskodeClient.kt
ā ā ā āāā EventSource.kt
ā ā āāā AndroidManifest.xml
ā āāā test/
āāā build.gradle.kts
āāā README.md
``