AKApiManager is a layer built on top of Alamofire to facilitate using restful api requests. This pod suits small and medium sized applications best.
AKApiManager can be installed using CocoaPods. Add the following lines to your Podfile:
pod 'AKApiManager'
You can also install it using swift package manager as well.
dependencies: [
.package(url: "https://github.com/AmrKoritem/AKApiManager.git", .upToNextMajor(from: "1.1.0"))
]
All you need is to set your base url before usage. For example, you can set it in the AppDelegate.application(_:didFinishLaunchingWithOptions:)
method.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
AKApiManager.shared.baseUrl = "https://www.example.com"
return true
}
For a simple api you can do just that:
let request = DataRequest(
url: "url-path",
method: .post // Any http method.
)
AKApiManager.shared.request(request)
You can also pass your body parameters as well as the api headers:
let request = DataRequest(
url: "url-path",
method: .post, // Any http method.
parameters: ["param1-key": "param1-value"],
headers: ["auth": "token"]
)
AKApiManager.shared.request(request) { responseStatus, response in
// Deal with the response here.
}
You can upload any data using:
let request = UploadRequest(
url: "url-path",
data: Data(),
fileName: "name",
mimeType: "file-type"
)
AKApiManager.shared.upload(request) { responseStatus, response in
// Deal with the response here.
}
You can check the example project here to see AKApiManager in action 🥳.
You can check a full set of examples here as well.
All contributions are welcome. Feel free to check the Known issues and Future plans sections if you don't know where to start. And of course feel free to raise your own issues and create PRs for them 💪
Thankfully, there are no known issues at the moment.
1 - Add a way for request cancelation.
Please check the license file.
link |
Stars: 0 |
Last commit: 2 weeks ago |
Fixing return type issue
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics