{"id":16835191,"url":"https://github.com/hackiftekhar/iqapiclient","last_synced_at":"2025-04-11T04:36:45.719Z","repository":{"id":56915126,"uuid":"304357453","full_name":"hackiftekhar/IQAPIClient","owner":"hackiftekhar","description":"Model-driven REST API Client","archived":false,"fork":false,"pushed_at":"2024-05-27T08:55:35.000Z","size":204,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T04:36:38.007Z","etag":null,"topics":["cocoapods","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackiftekhar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2020-10-15T14:46:28.000Z","updated_at":"2024-12-17T16:15:41.000Z","dependencies_parsed_at":"2023-02-12T02:46:50.701Z","dependency_job_id":"a4ed20d2-5958-41d3-bfb3-9a7183019603","html_url":"https://github.com/hackiftekhar/IQAPIClient","commit_stats":{"total_commits":23,"total_committers":2,"mean_commits":11.5,"dds":0.08695652173913049,"last_synced_commit":"7bedcb07c6c7c3dd5f89c1357607baf940af1991"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackiftekhar%2FIQAPIClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackiftekhar%2FIQAPIClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackiftekhar%2FIQAPIClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackiftekhar%2FIQAPIClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackiftekhar","download_url":"https://codeload.github.com/hackiftekhar/IQAPIClient/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345257,"owners_count":21088231,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cocoapods","swift"],"created_at":"2024-10-13T12:09:14.790Z","updated_at":"2025-04-11T04:36:45.688Z","avatar_url":"https://github.com/hackiftekhar.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"IQAPIClient\n==========================\nModel driven API Client\n\n[![Build Status](https://travis-ci.org/hackiftekhar/IQAPIClient.svg)](https://travis-ci.org/hackiftekhar/IQAPIClient)\n\nIQAPIClient allows us to make API requests and get back the responses in your defined model objects.\n\n## Requirements\n[![Platform iOS](https://img.shields.io/badge/Platform-iOS-blue.svg?style=fla)]()\n\n| Library                | Language | Minimum iOS Target | Minimum Xcode Version |\n|------------------------|----------|--------------------|-----------------------|\n| IQAPIClient            | Swift    | iOS 10.0           | Xcode 11              |\n\n#### Swift versions support\n5.0 and above\n\nInstallation\n==========================\n\n#### Installation with CocoaPods\n\n[![CocoaPods](https://img.shields.io/cocoapods/v/IQAPIClient.svg)](http://cocoadocs.org/docsets/IQAPIClient)\n\nIQAPIClient is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'IQAPIClient'\n```\n\n*Or you can choose the version you need based on the Swift support table from [Requirements](README.md#requirements)*\n\n```ruby\npod 'IQAPIClient', '1.0.0'\n```\n\n#### Installation with Source Code\n\n[![Github tag](https://img.shields.io/github/tag/hackiftekhar/IQAPIClient.svg)]()\n\n***Drag and drop*** `IQAPIClient` directory from demo project to your project\n\n#### Installation with Swift Package Manager\n\n[Swift Package Manager(SPM)](https://swift.org/package-manager/) is Apple's dependency manager tool. It is now supported in Xcode 11. So it can be used in all appleOS types of projects. It can be used alongside other tools like CocoaPods and Carthage as well. \n\nTo install IQAPIClient package into your packages, add a reference to IQAPIClient and a targeting release version in the dependencies section in `Package.swift` file:\n\n```swift\nimport PackageDescription\n\nlet package = Package(\n    name: \"YOUR_PROJECT_NAME\",\n    products: [],\n    dependencies: [\n        .package(url: \"https://github.com/hackiftekhar/IQAPIClient.git\", from: \"1.0.0\")\n    ]\n)\n```\n\nTo install IQAPIClient package via Xcode\n\n * Go to File -\u003e Swift Packages -\u003e Add Package Dependency...\n * Then search for https://github.com/hackiftekhar/IQAPIClient.git\n * And choose the version you would like\n\nBasic Configuration\n==========================\n\nWell, we'll have to do an initial configuration before using IQAPIClient like setting your API base urls and default headers etc. You can do it in your AppDelegate.\n\n\n```swift\n        IQAPIClient.baseURL = URL(string: \"https://www.example.com/api/v1\")\n        IQAPIClient.httpHeaders[\"Content-Type\"] = \"application/json\"\n        IQAPIClient.httpHeaders[\"Accept\"] = \"application/json\"\n```\n\nConfigure our Model\n==========================\n\nNow let's say you have an API which returns the list of users and you have a User model for that.\n\n```swift\nstruct User {\n\n    let id: Int\n\n    let name: String\n\n    let email: String?\n}\n```\n\nNow first, we need to modify our model to make it compatible to the IQAPIClient. To do this, we only have to confirm our User Model with the Decodable protocol and that's it.\n\n```swift\n// Now it's ready to be used with IQAPIClient\nstruct User: Decodable {\n\n    let id: Int\n\n    let name: String\n\n    let email: String?\n}\n```\n\nIQAPIClient Basic Method Signatures\n==========================\n\n#### Swift.Result version\n\n```swift\nstatic func sendRequest\u003cSuccess\u003e(\n            path: String,\n            method: HTTPMethod = .get,\n            parameters: Parameters? = nil,\n            completionHandler: @escaping\n            (_ result: Swift.Result\u003cSuccess, Error\u003e) -\u003e Void)\n```\n\nwhere native **Swift.Result** looks like this\n```swift\nenum Result\u003cSuccess, Failure\u003e where Failure: Error {\n    case success(Success)\t/// A success, storing a `Success` value.\n    case failure(Failure)\t/// A failure, storing a `Failure` value.\n}\n```\n\n#### IQAPIClient.Result version\n\n```swift\nstatic func sendRequest\u003cSuccess, Failure\u003e(\n            path: String,\n            method: HTTPMethod = .get,\n            parameters: Parameters? = nil,\n            completionHandler: @escaping \n            (_ result: IQAPIClient.Result\u003cSuccess, Failure\u003e) -\u003e Void)\n```\n\nwhere **IQAPIClient.Result** looks like this\n```swift\nenum Result\u003cSuccess, Failure\u003e {\n    case success(Success)\t/// A success, storing a `Success` value.\n    case failure(Failure)\t/// A failure, storing a `Failure` value.\n    case error(Error)\t\t/// An error, storing an `Error` value.\n}\n```\n\nAPI call using IQAPIClient\n==========================\n\nTo get list of users, there are a couple of ways you could use IQAPIClient.\n\n#### Method 1: Directly using the sendRequest method (Swift.Result version)\n\n```swift\nclass ViewController: UIViewController {\n\n    private func getUsersList() {\n        //Result\u003c[User], NSError\u003e detects that the app is asking for array of User object\n        IQAPIClient.sendRequest(path: \"/users\") { [weak self] (result: Swift.Result\u003c[User], NSError\u003e) in\n            switch result {\n            case .success(let users):\n                self?.users = users\n                self?.refreshUI()\n            case .failure(let error):\n                //Show error alert\n                print(error.localizedDescription)\n            }\n        }\n    }\n}\n```\n\n#### Method 2: Same request but with IQAPIClient.Result version\n\nLet's say APIMessage looks like below and we get this kind of response when something goes wrong\n\n```swift\nstruct APIMessage: Decodable {\n    let status: Bool\n    let code: Int\n    let message: String\n}\n```\n\n```swift\nclass ViewController: UIViewController {\n\n    private func getUsersList() {\n        //Result\u003c[User], NSError\u003e detects that the app is asking for array of User object\n        IQAPIClient.sendRequest(path: \"/users\") { [weak self] (result: Swift.Result\u003c[User], APIMessage\u003e) in\n            switch result {\n            case .success(let users):   //[User] object\n                self?.users = users\n                self?.refreshUI()\n            case .failure(let message): //APIMessage object\n                //Show failure alert\n                print(message.code)\n                print(message.message)\n            case .error(let error):     //Error object\n                //Show error alert\n                print(error.localizedDescription)\n            }\n        }\n    }\n}\n```\n\n#### Method 2: Moving this call to a function in IQAPIClient extension\n\n```swift\nextension IQAPIClient {\n\n    @discardableResult\n    static func getUsersList(completionHandler: @escaping (_ result: Swift.Result\u003cUser, NSError\u003e) -\u003e Void) -\u003e DataRequest {\n        return sendRequest(path: \"/users\", completionHandler: completionHandler)\n    }\n}\n```\n\n#### Method 3: If you don't have a Model yet, then you could also get the response in the form of Array of Dictionary like below:-\n\n```swift\nextension IQAPIClient {\n\n    @discardableResult\n    static func getUsersList(completionHandler: @escaping (_ result: Swift.Result\u003c[[String:Any]], NSError\u003e) -\u003e Void) -\u003e DataRequest {\n        return sendRequest(path: \"/users\", completionHandler: completionHandler)\n    }\n}\n\nclass ViewController: UIViewController {\n\n    private func getUsersList() {\n        \n        //Now use the getUsersList function\n        IQAPIClient.getUsersList { [weak self] result in\n            switch result {\n            case .success(let users):\n                self?.users = users\n                self?.refreshUI()\n            case .failure(let error):\n                //Show error alert\n                print(error.localizedDescription)\n            }\n        }\n    }\n}\n```\n\nAdvance Configuration\n==========================\n\n### Advance paramters of sendRequest method\n```\n- successSound: Bool = false  //A success sound/vibration will be played on success response, you could use it when you create some records like saving something in the server.\n- failedSound: Bool = false   //An error sound/vibration will be played on error \n- executeErroHandlerOnError: Bool = true  //This will also execute common error handler block on error to handle all error from a single place.\n```\n//TODO to add examples\n\nLICENSE\n---\nDistributed under the MIT License.\n\nContributions\n---\nAny contribution is more than welcome! You can contribute through pull requests and issues on GitHub.\n\nAuthor\n---\nIf you wish to contact me, email me: hack.iftekhar@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackiftekhar%2Fiqapiclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackiftekhar%2Fiqapiclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackiftekhar%2Fiqapiclient/lists"}