A swift package to interact with a REST API
Add https://github.com/GroupeMINASTE/APIRequest.swift.git
to your Swift Package configuration (or using the Xcode menu: File
> Swift Packages
> Add Package Dependency
)
// Import the package
import APIRequest
// When your app starts, set the default configuration
APIConfiguration.current = APIConfiguration(host: "api.example.com")
// And then call your API
// This is an equivalent to get `https://api.example.com/path/to/api?custom=parameter` and parse the response from JSON to a dictionary [String: String]
APIRequest("GET", path: "/path/to/api").with(name: "custom", value: "parameter").execute([String: String].self) { data, status in
// Check the data and status
if let data = data, status == .ok {
// Do what you want with your data
} else {
// Something went wrong, check the value of `status`
}
}
See the full documentation for a complete guide.
Check out the full example project made in a youtube tutorial.
Feel free to make a donation to help the developer to make more great content! Donate now
This package is also available for Android: APIRequest.java