@pluskode/client-ios
v0.1.2
Published
Pluskode Client SDK for iOS - Swift client with HTTP, WebSocket, SSE, gRPC, MQTT, and Binary Stream support
Downloads
20
Maintainers
Readme
Pluskode iOS Client SDK
Swift client SDK for Pluskode Backend Framework.
Status
✅ Core Implementation Complete - Basic structure and HTTP/WebSocket ready
Features
- ✅ HTTP client (URLSession)
- ✅ WebSocket client (URLSessionWebSocketTask)
- 🚧 SSE client (EventSource) - Basic structure
- ✅ gRPC client (HTTP-based)
- ✅ MQTT client (WebSocket-based)
- ✅ Binary stream support
- ✅ Auto-reconnect
- ✅ Offline queue
- ✅ Authentication (Bearer, Basic)
- ✅ Swift Concurrency (async/await)
Installation
Swift Package Manager
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/pluskode/client-ios.git", from: "0.1.0")
]Or in Xcode:
- File → Add Packages...
- Enter package URL:
https://github.com/pluskode/client-ios.git - Select version
CocoaPods
pod 'PluskodeClient', '~> 0.1.0'Usage
Basic Setup
import PluskodeClient
let client = PluskodeClient(
options: PluskodeClientOptions(
baseURL: "http://localhost:3000",
timeout: 30.0,
retries: 3
)
)
// Set authentication
client.setAuth(type: "Bearer", token: "your-jwt-token")HTTP Requests
// GET request
let users: [User] = try await client.get("/api/users")
// POST request
let newUser = try await client.post(
"/api/users",
data: [
"name": "John",
"email": "[email protected]"
]
)
// PUT, PATCH, DELETE
try await client.put("/api/users/123", data: ["name": "Jane"])
try await client.patch("/api/users/123", data: ["email": "[email protected]"])
try await client.delete<EmptyResponse>("/api/users/123")WebSocket
// Subscribe to channel
let unsubscribe = client.subscribe(channel: "chat/room1") { data in
print("Message: \(data)")
}
// Send message
try client.send(channel: "chat/room1", data: ["text": "Hello!"])
// Unsubscribe
unsubscribe()Server-Sent Events (SSE)
let unsubscribe = client.subscribeSSE(path: "/events/stream") { event in
print("Event: \(event.event ?? "message"), Data: \(event.data)")
}
// Close
unsubscribe()gRPC
let user = try await client.rpc(
service: "UserService",
method: "GetUser",
request: ["id": "123"]
) as UserMQTT
// Subscribe
let unsubscribe = client.subscribeMQTT(
topic: "sensors/temperature",
callback: { topic, message, qos in
print("\(topic): \(message) (QoS: \(qos))")
},
options: MQTTOptions(qos: 1)
)
// Publish
try await client.publishMQTT(
topic: "sensors/temperature",
message: "25.5",
options: MQTTOptions(qos: 1, retain: false)
)Binary Streams
let close = client.connectBinary(path: "/custom-protocol") { data in
print("Received \(data.count) bytes")
}
// Close
close()SwiftUI Example
import SwiftUI
import PluskodeClient
struct UsersView: View {
@State private var users: [User] = []
@State private var isLoading = false
let client = PluskodeClient(
options: PluskodeClientOptions(baseURL: "http://localhost:3000")
)
var body: some View {
List(users) { user in
Text(user.name)
}
.task {
isLoading = true
do {
users = try await client.get("/api/users")
} catch {
print("Error: \(error)")
}
isLoading = false
}
}
}Project Structure
client/ios/
├── Sources/
│ └── PluskodeClient/
│ ├── PluskodeClient.swift
│ └── EventSource.swift
├── Tests/
├── Package.swift
└── README.mdRequirements
- iOS 13.0+ / macOS 10.15+ / watchOS 6.0+ / tvOS 13.0+
- Swift 5.9+
- Xcode 15.0+
Dependencies
- Foundation (built-in)
- Combine (built-in)
Optional (for full gRPC/MQTT):
- gRPC-Swift
- CocoaMQTT
License
MIT
Note: This is a working implementation with core features. Full gRPC and MQTT native libraries can be added as optional dependencies.
