{"id":18046325,"url":"https://github.com/akxo/api-kit","last_synced_at":"2025-04-05T04:20:45.977Z","repository":{"id":162300009,"uuid":"636880179","full_name":"akxo/api-kit","owner":"akxo","description":"networking framework for making api calls","archived":false,"fork":false,"pushed_at":"2023-05-10T14:58:49.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T11:42:27.822Z","etag":null,"topics":["api","client","http","networking","requests","rest","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/akxo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2023-05-05T21:48:30.000Z","updated_at":"2023-05-09T14:51:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"2734dc37-9560-4738-89c9-22847766d641","html_url":"https://github.com/akxo/api-kit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akxo%2Fapi-kit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akxo%2Fapi-kit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akxo%2Fapi-kit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akxo%2Fapi-kit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akxo","download_url":"https://codeload.github.com/akxo/api-kit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247286330,"owners_count":20913955,"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","client","http","networking","requests","rest","swift"],"created_at":"2024-10-30T19:06:50.462Z","updated_at":"2025-04-05T04:20:45.954Z","avatar_url":"https://github.com/akxo.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# api-kit\na lightweight, flexible, and easy to use networking abstraction layer for making http requests\n\n## installation\n### swift package manager (spm)\n1. in xcode, select “file” → “add packages...”\n2. enter https://github.com/akxo/apikit\n### cocoapods\nadd the pod to your podfile\n```ruby\npod 'api-kit'\n```\ninstall pod\n```ruby\npod install\n```\n## usage\nimport the module\n```swift\nimport APIKit\n```\ncreate the api client with your baseurl\n```swift\nlet clientBuilder = APIClientBuilder(baseUrl: \"your-base-url-here\")\nlet client = clientBuilder.build()\n```\nthere are 3 methods for making network requests depending on your preference:\n1. completion handler\n```swift\nfunc load\u003cT\u003e(resource: Resource\u003cT\u003e, completion: @escaping (Result\u003cT, Error\u003e) -\u003e Void)\n```\n2. combine\n```swift\nfunc load\u003cT\u003e(resource: Resource\u003cT\u003e) -\u003e AnyPublisher\u003cT, Error\u003e\n```\n3. async/await\n```swift\nfunc load\u003cT\u003e(resource: Resource\u003cT\u003e) async -\u003e Result\u003cT, Error\u003e\n```\n### example 1 (GET movies)\ncreate response object (make sure it's decodable)\n```swift\nstruct APIMovie: Decodable {\n  let title: String\n  let director: String\n}\n```\nbuild resource\n```swift\nlet resource = Resource\u003c[APIMovie]\u003e(\n  jsonDecoder: JSONDecoder(),\n  path: \"/movies\",\n  method: .get,\n  params: [\"upcoming\": true]\n)\n```\nmake the request\n#### completion handler\n```swift\nclient.load(resource: resource) { result in\n  switch result {\n  case let .success(movies):\n    // handle movies\n  case let .failure(error):\n    // handle error\n  }\n}\n```\n#### combine\n```swift\nclient.load(resource: resource)\n  .sink { completion in\n    switch completion {\n    case .finished:\n      // handle completion\n    case let .failure(error):\n      // handle error\n    }\n  } receiveValue: { movies in\n    // handle movies\n  }\n```\n#### async/await\n```swift\nlet result = await client.load(resource: resource)\nswitch result {\ncase let .success(movies):\n  // handle movies\ncase let .failure(error):\n  // handle error\n}\n```\n### example 2 (POST movie)\nbuild resource\n```swift\nlet resource = Resource\u003cAPIMovie\u003e(\n  jsonDecoder: JSONDecoder(),\n  path: \"/movies\",\n  method: .post,\n  params: [\n    \"title\": \"inception\",\n    \"director\": \"christopher nolan\"\n  ]\n)\n```\nmake the request like above\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakxo%2Fapi-kit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakxo%2Fapi-kit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakxo%2Fapi-kit/lists"}