一个用于与 REST API 交互的 Swift 包/Android 库。
将 https://github.com/NathanFallet/APIRequest.git
添加到您的 Swift Package 配置中(或者使用 Xcode 菜单:File
> Swift Packages
> Add Package Dependency
)
将以下内容添加到您的 build.gradle
文件中
repositories {
mavenCentral()
}
dependencies {
implementation 'me.nathanfallet.apirequest:apirequest:1.0.4'
}
// 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`
}
}
请参阅完整文档以获取完整指南。
// When your app starts, set the default configuration
APIConfiguration.current = APIConfiguration("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
APIRequest("GET", "/path/to/api")
.with("custom", "parameter")
.execute { result, status ->
}
请参阅完整文档以获取完整指南。
查看完整示例项目,该项目是在一个Youtube 教程中制作的。
欢迎捐赠以帮助开发者制作更多优质内容!立即捐赠