The Satellite is an API communication module only for iOS written in Swift.
I welcome and appreciate contributions from the community. If you find a bug, have a feature request, or want to contribute code, please submit an issue or a pull request on our GitHub repository freely. Please see 💪 How to Contribute in Discussion tab.
Important
When you contribute code via pull request, please add the unit tests for your new functions.
The Satellite is released under the MIT license. See LICENSE for details.
- In your
Package.swift
Swift Package Manager manifest, add the following dependency to your dependencies argument:.package(url: "https://github.com/ku-ring/the-satellite.git, .branch("main")),
- Add the dependency to any targets you've declared in your manifest:
.target(name: "MyTarget", dependencies: ["Satellite"]),
To use the Satellite in your project, follow these steps:
- In Xcode, select File > Swift Packages > Add Package Dependency.
- In the search bar, paste the the Satellite URL: https://github.com/ku-ring/the-satellite
- Select the branch as main to install.
- Click Next, and then click Finish.
To use the Satellite in your project, add the following import statement at the top of your file:
import Satellite
"Version Sputnik" is the very first version of the Satellite, providing very basic public interfaces for API communication in Swift. It offers two main interfaces, one for Swift concurrency and another for Combine. Let's see how to use them.
See Also
Here is the class diagram for the Satellte: Sputnik
let satellite = Satellite(
host: "{BASE.URL}",
scheme: .http // default: `.https`
)
// Expected response object
struct CatFact: Codable {
let text: String
}
let satellite = Satellite(host: "cat-fact.herokuapp.com")
cancellable = statellite
.responsePublisher<ResponseType: [CatFact]>(
for: "facts/random",
httpMethod: .get,
queryItems: [
URLQueryItem(name: "animal_type", value: "cat"),
URLQueryItem(name: "amount", value: "2")
]
)
.sink(
receiveCompletion: { print ("Received completion: \($0).") },
receiveValue: { catFacts in print("Cat Facts: \(catFacts).")}
)
INFORMATION
For the more information on URLSession data task publisher, please see this link
let satellite = Satellite(host: "cat-fact.herokuapp.com")
let catFacts: [CatFact] = try await satellite.response(
for: "facts/random",
httpMethod: .get,
queryItems: [
URLQueryItem(name: "animal_type", value: "cat"),
URLQueryItem(name: "amount", value: "2")
]
)
self.text = catFacts
.compactMap { $0.text }
.joined(separator: ", ")
INFORMATION
For the more information on using async/await style, please see this link