{"id":28391432,"url":"https://github.com/viacominc/urlsessiondecodable","last_synced_at":"2025-06-25T21:31:25.327Z","repository":{"id":43794110,"uuid":"274914611","full_name":"ViacomInc/URLSessionDecodable","owner":"ViacomInc","description":"A swift package for adding decoding functionality to URLSession","archived":false,"fork":false,"pushed_at":"2024-08-07T12:22:38.000Z","size":46,"stargazers_count":4,"open_issues_count":2,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-31T19:34:57.619Z","etag":null,"topics":["decodable","spm","swift","urlsession"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ViacomInc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2020-06-25T12:48:39.000Z","updated_at":"2024-08-07T12:20:04.000Z","dependencies_parsed_at":"2024-08-02T11:19:40.762Z","dependency_job_id":null,"html_url":"https://github.com/ViacomInc/URLSessionDecodable","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/ViacomInc/URLSessionDecodable","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ViacomInc%2FURLSessionDecodable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ViacomInc%2FURLSessionDecodable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ViacomInc%2FURLSessionDecodable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ViacomInc%2FURLSessionDecodable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ViacomInc","download_url":"https://codeload.github.com/ViacomInc/URLSessionDecodable/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ViacomInc%2FURLSessionDecodable/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261955998,"owners_count":23235993,"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":["decodable","spm","swift","urlsession"],"created_at":"2025-05-31T09:13:13.428Z","updated_at":"2025-06-25T21:31:25.320Z","avatar_url":"https://github.com/ViacomInc.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://github.com/ViacomInc/URLSessionDecodable/workflows/Run%20tests/badge.svg?branch=master)\n\n# URLSessionDecodable\n\nA swift package for adding decoding functionality to `URLSession`. It is a very small but handful library, that solves the common pattern of deserialization of a response, and fallback on another message format in case of an HTTP error.\n\nWe have been using it in some form over the years at former Viacom, now [Paramount](https://www.paramount.com/). Since Swift Package Manager support in Xcode 11.0, we use it on production in several projects.\n\n## Installation\n\n### Swift Package Manager\n\nAdd to your `Package.swift`:\n\n```\ndependencies: [\n    .package(url: \"https://github.com/ViacomInc/URLSessionDecodable.git\", .upToNextMajor(from: \"0.1.0\"))\n]\n```\n\n## Usage\n\nExample usage, fetching a response that has a specific error format if error is handled by a backend:\n\n```\nstruct AnimalsResponse: Decodable {\n    let name: String\n}\n\nstruct AnimalsError: Error {\n    // optional, there are also other errors than the ones handled by a backend \n    let errorResponse: ErrorResponse? \n}\n\nstruct ErrorResponse: Decodable {\n    let userMessage: String\n}\n\nfunc getFavoriteAnimals(urlSession: URLSession = .shared,\n                        completionHandler: (Result\u003cAnimalsResponse, AnimalsError\u003e) -\u003e Void) -\u003e Cancelable {\n\t\n\tlet url = URL(string: \"https://myservice.com/favoriteAnimals\")!\n\treturn urlSession.decodableTask(with: url,\n\t                                method: .get,\n\t                                parameters: nil,\n\t                                headers: nil,\n\t                                decoder: JSONDecoder()) { result in\n\t    \n\t    switch result {\n\t    \tcase .success(let animals):\n\t    \t   completionHandler(.success(animals))\n\t    \tcase .failure(let error):\n\t    \t   let animalsFetchError: ErrorResponse? = error.decodeResponse(using: JSONDecoder())\n\t    \t   completionHandler(.failure(AnimalsError(errorResponse: animalsFetchError)))\n\t    }\n\t}\n}\n```\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## License\n\nURLSessionDecodable is released under the Apache 2.0 license. [See LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviacominc%2Furlsessiondecodable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fviacominc%2Furlsessiondecodable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fviacominc%2Furlsessiondecodable/lists"}