Swift SDK
Official Misar.Dev SDK for Swift — build, deploy, and manage apps via api.misar.io/dev.
The official Misar.Dev client SDK for Swift. Async/await based, with built-in retries and typed errors. Supports macOS 13+ and iOS 16+.
Installation
Add the package to your Package.swift:
// Package.swift
dependencies: [
.package(url: "https://github.com/misar-dev/misar-dev-swift.git", from: "1.0.0")
],
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "MisarDev", package: "misar-dev-swift")
]
)
]
Or in Xcode: File → Add Package Dependencies… and enter the repository URL.
Quick start
Initialize MisarDevClient with your API key (format mdk_…) and point it at the Misar.Dev API:
import MisarDev
let client = MisarDevClient(
apiKey: "mdk_your_api_key",
baseUrl: "https://api.misar.io/dev"
)
// List your projects
let projects = try await client.projectsList()
print(projects)
All methods are async and throw on failure.
Configuration
| Parameter | Default | Description |
|---|---|---|
apiKey | — | Required. Your API key (mdk_…). |
baseUrl | https://misar.dev/api | Set to https://api.misar.io/dev. |
maxRetries | 3 | Retry attempts for retryable errors (429, 5xx) with exponential backoff. |
session | .shared | Optional URLSession for dependency injection. |
The client sends Authorization: Bearer <apiKey> and Content-Type: application/json on every request.
Resources
This early v1.0.0 port implements the following methods. Each takes/returns loosely-typed JSON ([String: Any] / [[String: Any]]).
| Method | HTTP | Description |
|---|---|---|
projectsList() | GET /projects | List projects. |
projectsCreate(_ params:) | POST /projects | Create a project. |
templatesList() | GET /templates | List templates. |
apiKeysList() | GET /api-keys | List API keys. |
chatComplete(_ params:) | POST /chat | Send a chat completion request. |
usageGet() | GET /usage | Retrieve usage data. |
// Create a project
let project = try await client.projectsCreate([
"name": "my-app",
"template": "nextjs"
])
// Chat completion
let reply = try await client.chatComplete([
"messages": [["role": "user", "content": "Hello"]]
])
This is an early v1.0.0 port and intentionally exposes a subset of the full API surface (projects, templates, api-keys, chat, usage). Other resources available in the TypeScript SDK are not yet ported.
Error handling
All failures throw MisarDevError, an enum conforming to LocalizedError:
do {
let projects = try await client.projectsList()
} catch let error as MisarDevError {
switch error {
case .unauthorized(let msg): print("Auth failed: \(msg)")
case .rateLimited(let msg): print("Rate limited: \(msg)")
case .serverError(let code, let m): print("Server \(code): \(m)")
case .httpError(let code, let m): print("HTTP \(code): \(m)")
case .networkError(let e): print("Network: \(e)")
case .decodingError(let msg): print("Decode: \(msg)")
}
}
.rateLimited (429) and .serverError (500/502/503/504) are retried automatically up to maxRetries before being thrown.