{"id":13462666,"url":"https://github.com/uhooi/swift-http-client","last_synced_at":"2025-08-04T02:03:11.626Z","repository":{"id":44920782,"uuid":"391342092","full_name":"uhooi/swift-http-client","owner":"uhooi","description":"Communicate via HTTP easily in Swift.","archived":false,"fork":false,"pushed_at":"2022-07-02T12:56:20.000Z","size":64,"stargazers_count":15,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-05T03:11:53.365Z","etag":null,"topics":["http","http-client","ios","linux","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/uhooi.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}},"created_at":"2021-07-31T11:52:21.000Z","updated_at":"2024-08-11T17:51:12.000Z","dependencies_parsed_at":"2022-09-16T12:40:13.295Z","dependency_job_id":null,"html_url":"https://github.com/uhooi/swift-http-client","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/uhooi/swift-http-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhooi%2Fswift-http-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhooi%2Fswift-http-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhooi%2Fswift-http-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhooi%2Fswift-http-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uhooi","download_url":"https://codeload.github.com/uhooi/swift-http-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uhooi%2Fswift-http-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268639634,"owners_count":24282661,"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","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["http","http-client","ios","linux","swift"],"created_at":"2024-07-31T13:00:18.477Z","updated_at":"2025-08-04T02:03:11.555Z","avatar_url":"https://github.com/uhooi.png","language":"Swift","readme":"# swift-http-client\n\n[![CI](https://github.com/uhooi/swift-http-client/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/uhooi/swift-http-client/actions/workflows/main.yml)\n[![Release](https://img.shields.io/github/v/release/uhooi/swift-http-client)](https://github.com/uhooi/swift-http-client/releases/latest)\n[![CocoaPods Version](https://img.shields.io/cocoapods/v/UHIHTTPClient.svg)](https://cocoapods.org/pods/UHIHTTPClient)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/uhooi/swift-http-client)\n[![Swift Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fuhooi%2Fswift-http-client%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/uhooi/swift-http-client)\n[![Platform Compatibility](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fuhooi%2Fswift-http-client%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/uhooi/swift-http-client)\n[![License](https://img.shields.io/github/license/uhooi/swift-http-client)](https://github.com/uhooi/swift-http-client/blob/main/LICENSE)\n[![Twitter](https://img.shields.io/twitter/follow/the_uhooi?style=social)](https://twitter.com/the_uhooi)\n\nCommunicate via HTTP easily in Swift.\n\n## Table of Contents\n\n- [System requirements](#system-requirements)\n- [Installation](#installation)\n- [How to use](#how-to-use)\n- [Contribution](#contribution)\n- [Stats](#stats)\n\n## System requirements\n\n- Swift: 5.5+\n- Xcode: 13.0+\n- macOS: 11.3+\n\n## Installation\n\n### Swift Package Manager (Recommended)\n\n#### Package\n\nYou can add this package to `Package.swift`, include it in your target dependencies.\n\n```swift\nlet package = Package(\n    dependencies: [\n        .package(url: \"https://github.com/uhooi/swift-http-client\", .upToNextMajor(from: \"0.6.0\")),\n    ],\n    targets: [\n        .target(\n            name: \"\u003cyour-target-name\u003e\",\n            dependencies: [\"HTTPClient\"]),\n    ]\n)\n```\n\n#### Xcode\n\nYou can add this package on Xcode.\nSee [documentation](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app).\n\n### CocoaPods\n\nThis library is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your `Podfile`:\n\n```ruby\npod 'UHIHTTPClient', '~\u003e 0.6.0'\n```\n\n### Carthage\n\nThis library is available through [Carthage](https://github.com/Carthage/Carthage). To install it, simply add the following line to your `Cartfile`:\n\n```\ngithub \"uhooi/swift-http-client\" ~\u003e 0.6.0\n```\n\n## How to use\n\nYou can just import `HTTPClient` to use it.\n\n1. Implement a request body structure that conforms to the `Encodable` protocol. (Optional)\n    ```swift\n    struct RegisterUserRequestBody: Encodable {\n        let name: String\n        let description: String\n    }\n    ```\n\n2. Implement a response body structure that conforms to the `Decodable` protocol.\n    ```swift\n    struct RegisterUserResponseBody: Decodable {\n        let id: String\n    }\n    \n    extension RegisterUserResponseBody {\n        func convertToUserID() -\u003e UserID { .init(id: self.id) }\n    }\n    ```\n\n3. Implement a request structure that conforms to the `Request` protocol.\n    ```swift\n    import HTTPClient\n    \n    struct RegisterUserRequest: Request {\n        typealias ResponseBody = RegisterUserResponseBody\n        var path: String { \"user/create_user\" }\n        var httpMethod: HTTPMethod { .post }\n        var httpHeaders: [HTTPHeaderField: String]? { [.contentType: ContentType.applicationJson.rawValue] }\n    }\n    ```\n\n4. Create an instance of the `HTTPClient` class and call the `request` method.\n    ```swift\n    struct UserID: Identifiable, Equatable {\n        let id: String\n    }\n    ```\n\n    ```swift\n    protocol VersatileRepository {\n        func registerUser(name: String, description: String) async throws -\u003e UserID\n    }\n    ```\n\n    ```swift\n    import HTTPClient\n    \n    final class VersatileAPIClient {\n        static let shared = VersatileAPIClient()\n        \n        private let httpClient = HTTPClient(baseURLString: \"https://example.com/api/\")\n    }\n    \n    extension VersatileAPIClient: VersatileRepository {\n        func registerUser(name: String, description: String) async throws -\u003e UserID {\n            let requestBody = RegisterUserRequestBody(name: name, description: description)\n            let responseBody = try await httpClient.request(RegisterUserRequest(), requestBody: requestBody)\n            return responseBody.convertToUserID()\n        }\n    }\n    ```\n\n    ```swift\n    do {\n        let userID = try await VersatileAPIClient.shared.registerUser(name: \"Uhooi\", description: \"Green monster.\")\n        // Do something.\n    } catch {\n        // Do error handling.\n        print(error)\n    }\n    ```\n\n## Contribution\n\nI would be happy if you contribute :)\n\n- [New issue](https://github.com/uhooi/swift-http-client/issues/new)\n- [New pull request](https://github.com/uhooi/swift-http-client/compare)\n\n## Stats\n\n[![Stats](https://repobeats.axiom.co/api/embed/f2fa570e3daa9586ec48ddd7649e948f2f873f39.svg \"Repobeats analytics image\")](https://github.com/uhooi/swift-http-client)\n","funding_links":[],"categories":["Network API"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhooi%2Fswift-http-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuhooi%2Fswift-http-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuhooi%2Fswift-http-client/lists"}