{"id":1625,"url":"https://github.com/azizuysal/NetKit","last_synced_at":"2025-08-02T04:32:04.029Z","repository":{"id":62448915,"uuid":"52110662","full_name":"azizuysal/NetKit","owner":"azizuysal","description":"A Concise HTTP Framework in Swift","archived":false,"fork":false,"pushed_at":"2019-04-23T22:32:32.000Z","size":98,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-06T04:01:51.877Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/azizuysal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-02-19T19:19:51.000Z","updated_at":"2024-09-20T16:17:06.000Z","dependencies_parsed_at":"2022-11-01T23:06:30.939Z","dependency_job_id":null,"html_url":"https://github.com/azizuysal/NetKit","commit_stats":null,"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azizuysal%2FNetKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azizuysal%2FNetKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azizuysal%2FNetKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/azizuysal%2FNetKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/azizuysal","download_url":"https://codeload.github.com/azizuysal/NetKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228439027,"owners_count":17920017,"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-01-05T20:15:51.700Z","updated_at":"2024-12-06T08:31:20.467Z","avatar_url":"https://github.com/azizuysal.png","language":"Swift","funding_links":[],"categories":["Networking"],"sub_categories":["Video","Other free courses"],"readme":"[![Language](https://img.shields.io/badge/Swift-5.0-orange.svg)](http://swift.org)\n[![CocoaPods compatible](https://img.shields.io/badge/CocoaPods-compatible-brightgreen.svg)](https://cocoapods.org)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Build Status](https://travis-ci.org/azizuysal/NetKit.svg?branch=master)](https://travis-ci.org/azizuysal/NetKit)\n\n# NetKit\n\nA Concise HTTP Framework in Swift.\n\n## Requirements\n\nNetKit requires Swift 5.0 and Xcode 10.2\n\n## Installation\n\n### CocoaPods\n\nYou can use [CocoaPods](https://cocoapods.org) to integrate NetKit with your project.\n\nSimply add the following line to your `Podfile`:\n```ruby\npod \"NetKit\"\n```\n\nAnd run `pod update` in your project directory.\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.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate NetKit into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```yaml\ngithub \"azizuysal/NetKit\"\n```\n\nRun `carthage update` to build the framework and drag the built `NetKit.framework` into your Xcode project.\n\n### Manually\n\nYou can integrate NetKit manually into your project simply by dragging `NetKit.framework` onto Linked Frameworks and Libraries section in Xcode.\n\n## Usage\n\nIn order to run the included example project, you can install [JSON Server](https://github.com/typicode/json-server). It provides a quick backend for prototyping and mocking on your local machine. A sample `db.json` file is included in the example project.\n\nUse `WebService` to create a client for a particular web service and use it to make requests and process responses.\n\n```swift\nimport NetKit\n\nlet service = WebService(urlString: \"http://localhost:3000/\")\nservice.GET(\"/posts\")\n  .responseJSON { json in\n    print(json)\n    return .Success\n  }\n  .responseError { error in\n    print(error)\n  }\n  .resume()\n  ```\n\n`responseJSON()` is a convenience method and combines obtaining a response and converting to JSON into one step. You can also use `response()` method to obtain raw response data.\n\n```swift\n.response { data, response in\n  print(String(data: data!, encoding: NSUTF8StringEncoding))\n  return .Success\n}\n```\n\nYou can return `.Success` or `.Failure(ErrorType)` from the response handlers to signal error status and control will transfer to `.responseError()` in case of an error.\n\n### Synchronous Requests\n\nYou can use `resumeAndWait()` in order to make a synchronous request.\n\n```swift\nservice.PUT(\"/posts\")\n  .setPath(String(post.id))\n  .setJSON(post.toJson())\n  .responseJSON { json in\n    print(json)\n    return .Success\n  }\n  .responseError { error in\n    print(error)\n  }\n  .resumeAndWait()\n```\n\n### Authentication and SOAP support\n\nIf you need to set additional parameters, headers or authentication handlers, you can do so with Swift method chaining.\n\n```swift\nweatherService.POST()\n  .authenticate { (method, completionHandler) -\u003e WebTaskResult in\n    switch method {\n    case .Default, .HTTPBasic:\n      completionHandler(.UseCredential, NSURLCredential(user: loginId, password: password, persistence: .ForSession))\n    default:\n      completionHandler(.PerformDefaultHandling, nil)\n    }\n    return .Success\n  }\n  .setURLParameters([\"op\":\"GetCitiesByCountry\"])\n  .setSOAP(\"\u003cGetCitiesByCountry xmlns=\\\"http://www.webserviceX.NET\\\"\u003e\u003cCountryName\u003e\\(country)\u003c/CountryName\u003e\u003c/GetCitiesByCountry\u003e\")\n  .response { data, response in\n    print(String(data: data!, encoding: NSUTF8StringEncoding))\n    return .Success\n  }\n  .responseError { error in\n    print(error)\n  }\n  .resume()\n```\n\n### Support For All Configurations and Task Types\n\nYou can easily create `WebService` instances based on ephemeral or background sessions (the default is based on .defaultSessionConfiguration()).\n\n```swift\nlet service = WebService(urlString: baseURL, configuration: .ephemeralSessionConfiguration())\n```\n\nJust as easily, you can create upload or download tasks (the default is data task).\n\n```swift\nlet task = webService.GET(\"resource\", taskType: WebTask.TaskType.Download)\n```\n\n### Background Downloads\n\nYou can easily setup a background url session and create file download tasks.\n\n```swift\nlet webService: WebService = {\n  let configuration = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(\"com.azizuysal.netkit.test\")\n  configuration.requestCachePolicy = .ReloadIgnoringLocalAndRemoteCacheData\n  let service = WebService(urlString: baseURL, configuration: configuration)\n  return service\n}()\n```\n\nYou can use the convenient file download handler `responseFile()` to process downloaded files.\n\n```swift\ndownloadService.getFile()\n  .responseFile { (url, response) in\n    let path = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first?\n    if let url = url, response = response, filename = response.suggestedFilename, path = path?.URLByAppendingPathComponent(filename) {\n      do {\n        try NSFileManager.defaultManager().copyItemAtURL(url, toURL: path)\n      } catch let error as NSError {\n        print(error.localizedDescription)\n        return .Failure(error)\n      }\n    } else {\n      return .Failure(WebServiceError.BadData(\"Bad params\"))\n    }\n    notifyUser(DownloadService.FileDownloaded, filename: response?.suggestedFilename)\n    return .Success\n  }.responseError { error in\n    print((error as NSError).localizedDescription)\n    notifyUser(DownloadService.FileDownloaded, error: error)\n  }\n  .resumeAndWait()\n```\n\n##License\n\nThe MIT License (MIT)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazizuysal%2FNetKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazizuysal%2FNetKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazizuysal%2FNetKit/lists"}