The QuestradeAPI Swift library is built around two main components:
- Requestable – Defines API requests in an abstract way.
- Session – Manages and executes network requests.
Requestable
is a protocol that all API request types conform to. It acts as an abstraction over URLRequest
, where each API endpoint is represented by a concrete type conforming to Requestable
.
A RequestableHandler
is responsible for converting an abstract Requestable
into a concrete URLRequest
. It fetches data and decodes it into the associated Response
type.
By default, it uses DefaultBuilder
, but you can swap the builder using the public setter requestBuilder
.
- Constructs requests with no additional context.
- Requires a non-nil host; otherwise, it throws an error.
- Stores authentication tokens and host information for the current Questrade session.
- When set as the
requestBuilder
, it automatically authorizes all outgoing requests.
- Maps
Requestable
to a local JSON file found in theQuestradeAPIFakes
library. - If no matching file is found, an error is thrown.
Session
is a subclass of URLRequestHandler
that serves as the default method for processing all Requestable
requests.
ObservableObject
– Allows SwiftUI or Combine-based observers to react to changes.- Global error reporting – Exposes an
@Published errors
array. - Advanced logging & metrics – Can be customized via
URLSession
delegate initialization. - Authorization support – Manage auth states via
@Published var token
.
For an example project that runs on macOS, iOS, tvOS, watchOS, and visionOS; check out the included QuestradeAPIExample
Xcode project.
Task {
let request = QuotesRequest(symbolId: 8049)
// Implicit Request
let quotes = try await request().quotes
// Explicit Request
let quotes = try await Session.shared.perform(request).quotes
}
let streamTask = Task {
let request = QuotesRequest(symbolId: 8049)
for try await quote in request.stream {
print(quote.volumn)
}
}
// Stop Streaming
streamTask.cancel()
- Eli Slade - GitHub
This project is licensed under the MIT License - see the LICENSE.md file for details.