Swift
The Swift SDK for the GitHub REST API, generated from the same spec as the other nine.
Get the source
gh repo clone octri-dev/github-swift-showcase-sdkThe repository's README lists the toolchain and build commands for Swift. Open it on GitHub.
Quickstart
import Foundation
import Github
@main
struct Example {
static func main() async throws {
let config = ClientConfig(
baseUrl: "https://api.github.com"
)
let client = GitHubV3REST(config: config)
let result = try await client.search.labels(repositoryId: 1, q: "q")
print(result)
}
}Authentication
This build does not declare an authentication scheme. If the service requires a custom credential, set it through ClientAuthConfig.headers; those headers are merged into every request.
Client behavior
- Base URL:
https://api.github.com. - Transport: URLSession.
- Timeout: 600,000 ms per attempt.
- Retries: up to 3 attempts for status codes
408,409,429,500,502,503,504, with 500-8,000 ms backoff. - Idempotency: enabled for
POST,PATCHusingIdempotency-Key. - Error telemetry: off. This build has no reporting endpoint and sends no error reports.
High-level operation methods return the typed response body directly. The low-level request layer returns an SdkResponse<T> envelope containing data, status, headers, request ID, latency, and attempt count.
Errors
All failure paths use a small, predictable hierarchy:
| Error | Meaning |
|---|---|
SdkValidationError | A request argument failed an OpenAPI constraint before network I/O. |
SdkHttpError | The server returned a non-2xx response. |
SdkNetworkError | DNS, connection, TLS, or socket failure. |
SdkTimeoutError | The configured per-attempt timeout elapsed. |
HTTP errors expose statusCode, the response body and headers, plus requestId when the server supplies one. Preserve the request ID in support logs; it is the fastest way to correlate a failed SDK call with server-side traces.
Branch on common statuses with kind, which returns an SdkHttpErrorKind: .badRequest (400), .unauthorized (401), .permissionDenied (403), .notFound (404), .conflict (409), .unprocessableEntity (422), .rateLimit (429), .internalServer (any 5xx), or .other for any other status.
When the API declares a model for an error response, the SDK decodes the body into it as error.data, an any Decodable to narrow with as?. It is empty when the status declares no model or the body does not fit one. The raw body stays on the error either way, and try error.decodeBody(as: ErrorModel.self) decodes it into any ErrorModel by hand.