61 lines
1.6 KiB
Markdown
61 lines
1.6 KiB
Markdown
# ``ASConnectService``
|
|
|
|
A type-safe Swift client for the App Store Connect API.
|
|
|
|
## Overview
|
|
|
|
ASConnectService exposes every endpoint of Apple's App Store Connect API as a Swift method with typed requests and responses. It's generated from the official OpenAPI specification with [Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator).
|
|
|
|
### Creating a Client
|
|
|
|
Create a ``Client`` with a server URL, a transport, and a ``BearerAuthMiddleware`` that authenticates each request with a JSON Web Token (JWT):
|
|
|
|
```swift
|
|
import ASConnectService
|
|
import OpenAPIURLSession
|
|
|
|
let client = Client(
|
|
serverURL: try Servers.Server1.url(),
|
|
transport: URLSessionTransport(),
|
|
middlewares: [
|
|
BearerAuthMiddleware(token: yourJWTToken)
|
|
]
|
|
)
|
|
```
|
|
|
|
Tokens expire after 20 minutes at most. For longer-lived clients, pass a token provider instead, which is called on every request:
|
|
|
|
```swift
|
|
BearerAuthMiddleware {
|
|
try await tokenStore.validToken()
|
|
}
|
|
```
|
|
|
|
### Making API Calls
|
|
|
|
Each endpoint is a method on ``Client``, declared by ``APIProtocol``. It returns an `Output` enum with a case for each documented response:
|
|
|
|
```swift
|
|
let response = try await client.appsGetCollection(query: .init(limit: 10))
|
|
let apps = try response.ok.body.json.data
|
|
```
|
|
|
|
The `ok` property throws for any other response. To handle those, switch over the `Output` cases, such as `.unauthorized` or `.undocumented(statusCode:_:)`.
|
|
|
|
## Topics
|
|
|
|
### API Client
|
|
|
|
- ``Client``
|
|
- ``APIProtocol``
|
|
|
|
### Authentication
|
|
|
|
- ``BearerAuthMiddleware``
|
|
|
|
### Generated Types
|
|
|
|
- ``Components``
|
|
- ``Operations``
|
|
- ``Servers``
|