{"id":22192555,"url":"https://github.com/3sidedcube/httprequest","last_synced_at":"2025-06-15T09:32:47.433Z","repository":{"id":45023557,"uuid":"299445213","full_name":"3sidedcube/HTTPRequest","owner":"3sidedcube","description":"Model driven extension of Alamofire","archived":false,"fork":false,"pushed_at":"2023-08-01T09:52:08.000Z","size":3700,"stargazers_count":0,"open_issues_count":3,"forks_count":1,"subscribers_count":7,"default_branch":"develop","last_synced_at":"2025-01-30T01:22:39.089Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/3sidedcube.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":"2020-09-28T22:23:06.000Z","updated_at":"2021-12-16T22:52:52.000Z","dependencies_parsed_at":"2024-12-02T12:40:03.681Z","dependency_job_id":null,"html_url":"https://github.com/3sidedcube/HTTPRequest","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3sidedcube%2FHTTPRequest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3sidedcube%2FHTTPRequest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3sidedcube%2FHTTPRequest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/3sidedcube%2FHTTPRequest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/3sidedcube","download_url":"https://codeload.github.com/3sidedcube/HTTPRequest/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245351757,"owners_count":20601090,"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":[],"created_at":"2024-12-02T12:26:02.657Z","updated_at":"2025-03-24T20:45:46.128Z","avatar_url":"https://github.com/3sidedcube.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"## HTTPRequest \n\nA high level extension built on top of the awesome framework [Alamofire](https://github.com/Alamofire/Alamofire).  \nHow it works is best demonstrated by an example:\n\n```swift\n// Using Alamofire, make a request to the \"athlete\" endpoint\nStravaAPI.athlete.request { result in\n    // Map API result to result where the success is the model\n    let modelResult: Result\u003cAthlete, Error\u003e = result.modelResult()\n    switch modelResult {\n    case let .success(athlete):\n        // Use athlete\n    case let .failure(error):\n        // Handle error\n    }\n}\n```\n\nHere, we are making a HTTP request to the `\"athlete\"` endpoint of the Strava API and mapping to an `Athlete` model on success.\nThe details of the request can then be encapsulated in the `StravaAPI` `enum` (or anything that conforms to `HTTPRequestable`).\nHere's what that might look like:\n\n```swift\n/// Set of endpoints for the Strava API\nenum StravaAPI {\n\n    /// Fetch (logged in) `Athlete` based on authorization token\n    case athlete\n}\n\n/// Define a `HTTPRequest` based on the `StravaAPI` endpoint\nextension StravaAPI: HTTPRequestable {\n    \n    /// Map `StravaAPI` to a `HTTPRequest`\n    func httpRequest() throws -\u003e HTTPRequest {\n        switch self {\n        case .athlete:\n            return HTTPRequest(\n                method: .get,\n                urlComponents: .stravaAPI(endpoint: \"athlete\"),\n                additionalHeaders: HTTPHeaders(headers: [\n                    .acceptJSON,\n                    .authorization\n                ])\n            )\n        }\n    }\n}\n\n/// `URLComponents` template for Strava API HTTP requests\nextension URLComponents {\n    \n    /// Strava API for `endpoint` and `queryItems`\n    ///\n    /// - Parameters:\n    ///   - endpoint: `String`\n    ///   - queryItems: `[URLQueryItem]`\n    static func stravaAPI(\n        endpoint: String,\n        queryItems: [URLQueryItem] = []\n    ) -\u003e URLComponents {\n        var urlComponents = URLComponents()\n        urlComponents.scheme = \"https\"\n        urlComponents.host = \"www.strava.com\"\n        urlComponents.path = \"/api/v3/\\(endpoint)\"\n        urlComponents.queryItems = queryItems\n        return urlComponents\n    }\n}\n```\n\n## Installation\n\n### Swift Package Manager\n\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. To integrate into your project using Swift Package Manager, specify it in the `dependencies` of your `Package.swift`:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/3sidedcube/HTTPRequest.git\", .upToNextMajor(from: \"1.0.0\"))\n]\n```\n\n### Carthage\n\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"3sidedcube/HTTPRequest\" ~\u003e 1.0.0\n```\n\n### CocoaPods\n\n[CocoaPods](https://cocoapods.org) is a dependency manager for Cocoa projects. To integrate into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\npod 'HTTPRequest', :git =\u003e 'https://github.com/3sidedcube/HTTPRequest.git', :tag ~\u003e '1.0.0'\n```\n\n### Notes\n\nConverting from a `HTTPRequest` to a `URLRequest` may `throw` an `Error`. One example might be: the `URL` path component is invalid.\nIt's also very possible for a request to fail while building it, for example, failed to create JSON request body due to an encoding error.\n\nThe Strava API is just an example here, you can define your API endpoints however you want! It's the conformance to the `HTTPRequestable` that's important.\n\nThe framework is meant to be lightweight, it's essentially a higher layer of abstraction on top of Alamofire.\n\n## Contributing\n\nThe (dependent) frameworks for `HTTPRequest` are installed via [Carthage](https://github.com/Carthage/Carthage) as `xcframework`s.\nSimply run `./scripts/install.sh` to run the project locally.\n\n## Example\n\n`StravaAPI` is an example project which hits the Strava API using `HTTPRequest`.\nAs this API is authenticated, the setup requires providing a `TokenRefresh.json` file with the properties needed to fetch an authentication token. \nYou can find these details by:\n- Logging in to Strava\n- Go to \"Settings\"\n- Click on \"My API Application\"\n\nThe JSON should look like so:\n```json\n{\n  \"client_id\": 123456789,\n  \"refresh_token\": \"{yourRefreshToken}\",\n  \"client_secret\": \"{yourClientSecret}\",\n  \"grant_type\": \"refresh_token\"\n}\n```\nNote the `grant_type` is a fixed value here, the other properties will need updating.\nAdd this JSON  into a directory named `StravaToken` in the `PROJECT_DIR` (where the `.xcodeproj` file is located). \nThe JSON file path should be: `${PROJECT_DIR}/StravaToken/TokenRefresh.json`.\nNote, this directory is ignored by `git`.\n\nAs the Strava API authenticates using an OAuth flow, the first launch will require granting permission in a browser and and initializing with the code returned on success.\nThen you are ready to go!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3sidedcube%2Fhttprequest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F3sidedcube%2Fhttprequest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F3sidedcube%2Fhttprequest/lists"}