{"id":15293518,"url":"https://github.com/rauhul/api-manager","last_synced_at":"2025-02-23T12:32:12.518Z","repository":{"id":56900876,"uuid":"88953456","full_name":"rauhul/api-manager","owner":"rauhul","description":"Framework for abstracting RESTful api requests  ","archived":false,"fork":false,"pushed_at":"2021-03-25T07:46:23.000Z","size":1142,"stargazers_count":15,"open_issues_count":2,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-19T03:02:07.395Z","etag":null,"topics":["api","apimanager","cocoapods","swift","swift-package","xcode"],"latest_commit_sha":null,"homepage":"https://rauhul.me/api-manager","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/rauhul.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-21T07:08:29.000Z","updated_at":"2024-09-26T16:05:27.000Z","dependencies_parsed_at":"2022-08-20T18:20:53.002Z","dependency_job_id":null,"html_url":"https://github.com/rauhul/api-manager","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rauhul%2Fapi-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rauhul%2Fapi-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rauhul%2Fapi-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rauhul%2Fapi-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rauhul","download_url":"https://codeload.github.com/rauhul/api-manager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240317341,"owners_count":19782384,"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":["api","apimanager","cocoapods","swift","swift-package","xcode"],"created_at":"2024-09-30T16:49:50.692Z","updated_at":"2025-02-23T12:32:12.188Z","avatar_url":"https://github.com/rauhul.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# APIManager\n[![Swift Version](https://img.shields.io/badge/swift-v5.0-orange.svg)](https://github.com/apple/swift)\n[![Build Status](https://travis-ci.org/rauhul/api-manager.svg?branch=master)](https://travis-ci.org/rauhul/api-manager)\n[![Documentation Converage](https://raw.githubusercontent.com/rauhul/api-manager/master/docs/badge.svg?sanitize=true)](https://rauhul.me/api-manager/)\n[![Release Version](https://img.shields.io/badge/release-v0.4.0-ff69b4.svg)](https://github.com/rauhul/api-manager/releases)\n[![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/rauhul/api-manager/master/LICENSE)\n\nAPIManager is a framework for abstracting RESTful API requests.\n\n## Requirements\n- Swift 5.0+\n\n### Notes\n- APIManager 0.3.0 is the last version that supports cocoapods\n- APIManager 0.3.0 is the last release with Swift 4.2 support\n- APIManager 0.0.5 is the last release with Swift 3 support\n\n## Installation\n\n### Swift Package Manager\nThe [Swift Package Manager](https://swift.org/package-manager/) is a tool for automating the distribution of Swift code and is integrated into the `swift` compiler.\n\nOnce you have your Swift package set up, adding APIManager as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.\n\n```swift\ndependencies: [\n    .Package(url: \"https://github.com/rauhul/api-manager.git\", from: \"0.4.0\")\n]\n```\n\n## Usage\nAPIManager relies on users to create `APIServices` and  `APIReturnable` types relevent to the RESTful APIs they are working with. `APIServices` contain descriptions of various endpoints that return their responses as native swift objects.\n\n### Making an APIReturnable Type\n\nAn APIReturnable Type only needs to conform to one method  `init(from: Data) throws`. APIManager extends `Decodable` types to also be `APIReturnable`. An example implementation can be found below:\n\n```swift\nextension APIReturnable where Self: Decodable {\n    init(from data: Data) throws {\n        self = try JSONDecoder().decode(Self.self, from: data)\n    }\n}\n```\n\n### Making an APIService\nAn APIService is made up of 3 components.\n\n1. A `baseURL`. Endpoints in this service will be postpended to this URL segment. As a result a baseURL will generally look like the root URL of the API the service communicates with.\n\n```swift\nopen class var baseURL: String {\n    return \"https://api.example.com\"\n}\n```\n\n2. `HTTPHeaders` to be sent alongside the `APIRequest`s made by the endpoints in your `APIService`.\n\n```swift\nopen class var headers: HTTPHeaders? {\n    return [\n        \"Content-Type\": \"application/json\"\n    ]\n}\n\n```\n\n3. A set of RESTful api endpoints that you would like to use. These should be simple wrappers around the `APIRequest` constructor that can take in data (as `HTTPParameters` and/or `HTTPBody` as a json dictionary `[String: Any]`). For example if you would like to get user information by id, the endpoint may look like this:\n\n```swift\nopen class func getUser(byId id: Int) -\u003e APIRequest\u003cExampleReturnType\u003e {\n    return APIRequest\u003cExampleReturnType\u003e(service: Self, endpoint: \"/users\", params: [\"id\": id], body: nil, method: .GET)\n}\n\n```\n\n### Using an APIService\nNow that you have an `APIService`, you can use it make RESTful API Requests.\n\nAll the RESTful API endpoints we need to access should already be defined in our `APIService`, so using them is simply a matter of calling them.\n\nUsing the example service above, we can make a request to get the User associated with the id 452398:\n\n```swift\nlet request = ExampleService.getUser(byId: 452398)\n```\n\nAnd subsecquently perform the `APIRequest` with:\n\n```swift \nrequest.perform(withAuthorization: nil)\n```\n\nHowever, this leaves us unable to access the response nor potential error and additionally requires multiple lines to do what is really one action. Conveniently `APIManager` allows us to solve this problems with simple chaining syntax. We can specify success, cancellation, and failure blocks. This new request is seen below:\n\n```swift\nExampleService.getUser(byId: 452398)\n.onSuccess { (returnValue: ReturnType) in\n    // Handle Success (Background thread)\n    DispatchQueue.main.async {\n        // Handle Success (main thread)\n    }\n}\n.onFailure { (error) in\n    // Handle Failure (Background thread)\n    DispatchQueue.main.async {\n        // Handle Failure (main thread)\n    }\n}\n.perform(withAuthorization: nil)\n```\n\n## Support\nPlease [open an issue](https://github.com/rauhul/api-manager/issues/new) for support.\n\n## Contributing\nPlease contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://github.com/rauhul/api-manager/compare/).\n\n## License\nThis project is licensed under the MIT License. For a full copy of this license take a look at the LICENSE file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frauhul%2Fapi-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frauhul%2Fapi-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frauhul%2Fapi-manager/lists"}