Misar Docs
MisarMailMisar.BlogMisarReachMisarPostMisar.DevMisar PlatformMisar IdentityMisar Posts API
Sdks

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

ParameterDefaultDescription
apiKeyRequired. Your API key (mdk_…).
baseUrlhttps://misar.dev/apiSet to https://api.misar.io/dev.
maxRetries3Retry attempts for retryable errors (429, 5xx) with exponential backoff.
session.sharedOptional 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]]).

MethodHTTPDescription
projectsList()GET /projectsList projects.
projectsCreate(_ params:)POST /projectsCreate a project.
templatesList()GET /templatesList templates.
apiKeysList()GET /api-keysList API keys.
chatComplete(_ params:)POST /chatSend a chat completion request.
usageGet()GET /usageRetrieve 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.