{"id":15561337,"url":"https://github.com/asaday/ezhttp","last_synced_at":"2025-04-23T22:29:36.676Z","repository":{"id":56910253,"uuid":"62477925","full_name":"asaday/EzHTTP","owner":"asaday","description":"Swift HTTP access library","archived":false,"fork":false,"pushed_at":"2021-04-21T02:27:49.000Z","size":212,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T10:47:48.617Z","etag":null,"topics":["networking","swift","swift4","urlrequest","urlsession","xcode"],"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/asaday.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":"2016-07-03T02:23:59.000Z","updated_at":"2021-04-21T02:23:29.000Z","dependencies_parsed_at":"2022-08-21T04:20:38.132Z","dependency_job_id":null,"html_url":"https://github.com/asaday/EzHTTP","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asaday%2FEzHTTP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asaday%2FEzHTTP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asaday%2FEzHTTP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asaday%2FEzHTTP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asaday","download_url":"https://codeload.github.com/asaday/EzHTTP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250526047,"owners_count":21445122,"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":["networking","swift","swift4","urlrequest","urlsession","xcode"],"created_at":"2024-10-02T16:07:30.802Z","updated_at":"2025-04-23T22:29:36.657Z","avatar_url":"https://github.com/asaday.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EzHTTP\n\n[![Build Status](https://travis-ci.org/asaday/EzHTTP.svg?branch=master)](https://travis-ci.org/asaday/EzHTTP)\n[![Version Status](https://img.shields.io/cocoapods/v/EzHTTP.svg?style=flat)](http://cocoadocs.org/docsets/EzHTTP)\n[![Platform](http://img.shields.io/cocoapods/p/EzHTTP.svg?style=flat)](http://cocoapods.org/?q=EzHTTP)\n\nEzHTTP is easy-to-use library for HTTP access for your iOS application.\n\n- simplest API\n- auto make request (query,form,json)\n- useful response (use as string,json,data)\n- auto indicator show/hide\n- log,stub handler\n- escape App-Transport-Security\n- short code\n\n## Requirements\n\n- iOS 9.0+\n- Xcode 11+\n\n## Installation\n\n### CocoaPods\n\nTo install EzHTTP with CocoaPods, add EzHTTP to the devendencies in your **Podfile**.\n\n    pod 'EzHTTP'\n\nThen, run `pod install` command in your project.\n\n### Swift Package Manager\n\nYou can also install EzHTTP using Swift Package Xcode11 later\n\nFile-\u003eSwift Packages-\u003eAdd Package Dependency...\n\n    https://github.com/asaday/EzHTTP.git\n\n## Usage\n\nBegin by importing the EzHTTP.\n\n    import EzHTTP\n\n### Request\n\nSimple GET request\n\n    HTTP.get(\"https://httpbin.org/get\") { print($0.string) }\n\nPOST with form\n\n    HTTP.request(.POST, \"https://httpbin.org/post\", params: [\"form1\": \"TEST\"]) {}\n\n    // auto appended header \"Content-Type: application/x-www-form-urlencoded; charset=utf-8\"\n    // or if included HTTP.MultipartFile() , header is \"multipart/form-data; boundary=...\"\n\nPOST with JSON\n\n    HTTP.request(.POST, \"https://httpbin.org/post\", json: [\"foo\": \"bar\"]) {}\n\n    // auto appended header \"Content-Type: application/json\"\n\nPOST with custom Headers\n\n    HTTP.request(.POST, \"https://httpbin.org/post\",headers: [\"Custom-Content\":\"HAHAHA\"])\n\nPOST with raw data\n\n    // data is String or Data\n\n    HTTP.request(.POST, \"https://httpbin.org/post\", body: data, headers:[\"Content-Type\": \"application/atom+xml\"]) {}\n\nOther methods\n\n    HTTP.request(.DELETE, \"https://httpbin.org/delete\") {}\n\n- OPTIONS, GET, HEAD, POST, PUT, PATCH, DELETE, TRACE, CONNECT\n\nCreate a request\n\n    let req:NSMutableURLRequest = HTTP.createRequest(.GET, \"https://httpbin.org/get\", params: [:], headers: [:])\n    HTTP.request(req!){}\n\nsync\n\n    let r = HTTP.getSync(\"https://httpbin.org/get\")\n    print(r.string)\n\n### Response body\n\n- data\n- error\n- response\n\n##### Retrieve as String\n\n- `$0.string` String?\n- `$0.stringValue` String\n\n##### JSON\n\n- `$0.jsonObject` NSObject? (json decoded)\n- `$0.jsonObjectValue` NSObject (json decoded)\n\n##### Data\n\n- `$0.data` Data?\n- `$0.dataValue` Data\n\n##### Error\n\n- `if let error = $0.error {...}`\n\n##### misc\n\n- `status` Int Response status code\n- `headers` [String: String] Response headers\n- `duration`\n- `request`\n- `description`\n- `retriedCount`\n\n### Request make\n\n    let req:NSMutableURLRequest = HTTP.create(.GET,\"https://httpbin.org/\", params: \t[\"foo\":\"bar\"],headers: [\"Custom-Content\":\"HAHAHA\"])\n\n#### params\n\n##### normal\n\n| method         | in param                                              |\n| -------------- | ----------------------------------------------------- |\n| GET            | query                                                 |\n| POST,PUT       | application/x-www-form-urlencoded or application/json |\n| POST with file | multipart/form-data                                   |\n\nchange to JSON POST `HTTP.shard.postASJSON = true`\n\nto use file, add in params HTTP.MultipartFile, auto changed to multipart/form-data\n\nin json mode, data is auto convered to base64\n\n##### on demand change request params mode\n\nuse HTTP.makeParams() or\n\n    params = [HTTP.ParamMode.query.rawValue: [\"foo\":bar\"],\n    \t\tHTTP.ParamMode.form.rawValue: [\"aaa\":\"bbb\"]]\n\n- ParamMode\n\n| key           | description                          |\n| ------------- | ------------------------------------ |\n| query         | in query ?aaa=bbb                    |\n| form          | as application/x-www-form-urlencoded |\n| json          | as application/json                  |\n| multipartForm | as multipart/form-data; boundary=... |\n| path          | in path https://example.com/{user}   |\n| header        | in header                            |\n\n- path example\n\n  URLstring = \"https://example.com/{user}\"  \n  param = [HTTP.ParamMode.path.rawValue: [\"user\": \"123\"]]\n\nmake URL as\n\n    \"https://example.com/123\"\n\n### Log,Stub,Retry\n\n    var errorHandler: ((result: Response) -\u003e Void)?\n    var successHandler: ((result: Response) -\u003e Void)?\n    var logHandler: ((result: Response) -\u003e Void)?\n    var stubHandler: ((request: NSURLRequest) -\u003e Response?)?\n    var retryHandler: ((_ result: Response) -\u003e Bool)?\n\nto use\n\n    HTTP.shared.logHandler = { print($0.stringValue) }\n\nor you can use preset handler\n\n    HTTP.shared.logHandler = HTTP.defaultLogHandler\n    HTTP.shared.retryHandler = HTTP.defaultRetryHandler\n\nretry hanlder example\n\n    HTTP.shared.retryHandler = { return $0.retriedCount \u003c 3 }\n\n| kind    | desc                                                                |\n| ------- | ------------------------------------------------------------------- |\n| error   | called at error                                                     |\n| success | called at success                                                   |\n| log     | every called                                                        |\n| stub    | call and get response. if response is nil, do as normal http access |\n| retry   | judge retry                                                         |\n\n### self signed SSL\n\nIf you want to use self signed SSL authentication, make the following settings.\n\nset Allow Arbitrary Loads = YES\n\nand\n\n    HTTP.shared.allowSelfSignedSSL = true\n\n### ATS escape\n\nATS(AppTransportSecurity) is enabled(default) and call as http://, request to server as socket connection (not use NSURLSession,NSURLConnection :-)\n\n    HTTP.shared.escapeATS = true // default is false\n\n    HTTP.get(\"http://httpbin.org/get\") {\n    \tprint($0.string)\n    }\n\nauto checked NSAllowsArbitraryLoads and NSExceptionAllowsInsecureHTTPLoads/NSExceptionDomains\n\n- protocol HTTP/1.1\n- cookie managed (NSHTTPCookieStorage.sharedHTTPCookieStorage)\n- auto redirect\n- redirect to HTTPS, auto changed to use NSURLSession\n- chunked mode (stream)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasaday%2Fezhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasaday%2Fezhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasaday%2Fezhttp/lists"}