{"id":1628,"url":"https://github.com/imex94/NetworkKit","last_synced_at":"2025-08-02T04:32:01.177Z","repository":{"id":62448959,"uuid":"53584544","full_name":"imex94/NetworkKit","owner":"imex94","description":"Lightweight Networking and Parsing framework made for iOS, Mac, WatchOS and tvOS.","archived":false,"fork":false,"pushed_at":"2018-02-03T11:17:56.000Z","size":1420,"stargazers_count":31,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-15T16:26:54.898Z","etag":null,"topics":[],"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/imex94.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-03-10T12:58:01.000Z","updated_at":"2024-11-04T05:09:49.000Z","dependencies_parsed_at":"2022-11-01T23:46:48.573Z","dependency_job_id":null,"html_url":"https://github.com/imex94/NetworkKit","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/imex94/NetworkKit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imex94%2FNetworkKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imex94%2FNetworkKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imex94%2FNetworkKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imex94%2FNetworkKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imex94","download_url":"https://codeload.github.com/imex94/NetworkKit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imex94%2FNetworkKit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268334615,"owners_count":24233793,"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-02T02:00:12.353Z","response_time":74,"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":[],"created_at":"2024-01-05T20:15:51.777Z","updated_at":"2025-08-02T04:32:00.808Z","avatar_url":"https://github.com/imex94.png","language":"Swift","funding_links":[],"categories":["Networking"],"sub_categories":["Video","Other free courses"],"readme":"\u003cp align= \"center\"\u003e\n  \u003cimg src=\"https://github.com/imex94/NetworkKit/blob/master/images/networkKit.png\" /\u003e\n\u003c/p\u003e\n\n# NetworkKit ![License MIT](https://go-shields.herokuapp.com/license-MIT-blue.png)\n\n[![Build Status](https://travis-ci.org/imex94/NetworkKit.svg?branch=master)](https://travis-ci.org/imex94/NetworkKit)\n[![Available devices](https://camo.githubusercontent.com/30f3ea607a65990e8cf2d6e11a48602167399324/68747470733a2f2f636f636f61706f642d6261646765732e6865726f6b756170702e636f6d2f702f41464e6574776f726b696e672f62616467652e706e67)]()\n[![Version](https://img.shields.io/cocoapods/v/NetworkKit.svg?style=flat)](http://cocoapods.org/pods/NetworkKit)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\nA lightweight iOS, Mac and Watch OS framework that makes networking and parsing super simple. Uses the open-sourced [JSONHelper](https://github.com/isair/JSONHelper) with functional parsing. For networking the library supports basic **GET**, **POST**, **DELETE** HTTP requests.\n\n## Install\n\n### Cocoapods\n\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects. You can install it with the following command:\n\n```\n$ gem install cocoapods\n```\n\nTo install it, simply add the following line to your ```Podfile```:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\nuse_frameworks!\n\npod 'NetworkKit'\n```\n\nThen run the folloring command:\n\n```\n$ pod install\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.\n\nYou can install Carthage with [Homebrew](http://brew.sh) using the following command:\n\n```\n$ brew update\n$ brew install carthage\n```\n\nTo integrate NetworkKit into your Xcode project using Carthage, add it into your ```Cartfile```:\n\n```\ngithub \"imex94/NetworkKit\" ~\u003e 1.3\n```\n\nRun ```carthage update``` to build the framework and drag the built ```NetworkKit.framework``` into your Xcode project under **Target** - **General** - **Embedded binaries**:\n\n![Import Framework](https://github.com/imex94/NetworkKit/blob/master/images/import2.png \"Import Framework\")\n\n## Usage\n\n**NetworkKitExample** project provides a guidance to get started.\n\nFor the purpose of this example, let say we want to download one of the stories from Hacker News. For this let's use their API endpoint - https://hacker-news.firebaseio.com/v0/item/11245652.json?print=pretty, which give us the following **JSON** response:\n\n\n[![Run in Postman](https://run.pstmn.io/button.svg)](https://www.getpostman.com/run-collection/aa59a52596f959def779)\n\n```json\n{\n  \"by\": \"jergason\",\n  \"id\": 11245652,\n  \"kids\": [\n    11245801,\n    11245962,\n    11250239,\n    11246046\n  ],\n  \"time\": 1457449896,\n  \"title\": \"CocoaPods downloads max out five GitHub server CPUs\",\n  \"type\": \"story\"\n}\n```\nWe want to deserialize the JSON response above to **Swift object**. To do this, we need a **struct** that conforms the protocol **Deserializable** and implement the **required init(data: [String: AnyObject])** constructor and use the deserialization operator (`\u003c--`):\n\n```swift\nimport NetworkKit\n```\n\n```swift\nstruct NKItem: Deserializable {\n    var id: Int?\n    var username: String?\n    var kids: [Int]?\n    var title: String?\n    var type: String?\n    var date: NSDate?\n\n    init(data: [String : AnyObject]) {\n        id \u003c-- data[\"id\"]\n        username \u003c-- data[\"by\"]\n        kids \u003c-- data[\"kids\"]\n        title \u003c-- data[\"title\"]\n        type \u003c-- data[\"type\"]\n        date \u003c-- data[\"time\"]\n    }\n}\n```\n\nTo connect to an API and perform a **GET** request is simple and intuitive and parsing is like **magic**:\n\n```swift\nNKHTTPRequest.GET(\n  \"https://hacker-news.firebaseio.com/v0/item/11245652.json\",                \n  params: [\"print\": \"pretty\"],\n  success: { data in\n      var item: NKItem?\n      item \u003c-- data                                        \n  },\n  failure: { error in\n      print(error.message)\n  })\n```\n\n## API\n\n### Networking\n\n#### GET\nA simple HTTP GET method to get request from a url.\n\n**urlString** - `String` \u003cbr /\u003e\nThe string representing the url. \u003cbr /\u003e\n\n\u003c!-- **auth (Optional)** - `NKOauth?` \u003cbr /\u003e\nAdd Oauth 2.0 when the API requires one. Just specify the consumerKey and consumer Secret, like this\nNKOauth(consumerKey: \"\", consumerSecret: \"\"). \u003cbr /\u003e --\u003e\n\n**params (Optional)** - `[NSObject: AnyObject]?` \u003cbr /\u003e\nThe parameters you need to pass with the GET method. Everything after '?'. \u003cbr /\u003e\n\n**success** - `((AnyObject) -\u003e Void)` \u003cbr /\u003e\nSuccessful closure in case the request was successful. \u003cbr /\u003e\n\n**failure** -  `((NKHTTPRequestError) -\u003e Void)` \u003cbr /\u003e\nFailure Closure which notifies if any error has occurred during the request. \u003cbr /\u003e\n\n#### POST\nA simple HTTP POST method to post a resource to the url.\n\n**urlString** - `String` \u003cbr /\u003e\nThe string representing the url.\n\n\u003c!-- **auth (Optional)** - `NKOauth?` \u003cbr /\u003e\nAdd Oauth 2.0 when the API requires one. Just specify the consumerKey and consumer Secret, like this\nNKOauth(consumerKey: \"\", consumerSecret: \"\"). \u003cbr /\u003e --\u003e\n\n**params (Optional)** - `[NSObject: AnyObject]?` \u003cbr /\u003e\nThe body you need to pass with the POST method. Resources you want to pass. \u003cbr /\u003e\n\n**success** - `((AnyObject) -\u003e Void)` \u003cbr /\u003e\nSuccessful closure in case the request was successful. \u003cbr /\u003e\n\n**failure** -  `((NKHTTPRequestError) -\u003e Void)` \u003cbr /\u003e\nFailure Closure which notifies if any error has occured during the request. \u003cbr /\u003e\n\n#### DELETE\nA simple HTTP DELETE method to delete a resource from the server.\n\n**urlString** - `String` \u003cbr /\u003e\nThe string representing the url. \u003cbr /\u003e\n\n\u003c!-- **auth (Optional)** - `NKOauth?` \u003cbr /\u003e\nAdd Oauth 2.0 when the API requires one. Just specify the consumerKey and consumer Secret, like this\nNKOauth(consumerKey: \"\", consumerSecret: \"\"). \u003cbr /\u003e --\u003e\n\n**params (Optional)** - `[NSObject: AnyObject]?` \u003cbr /\u003e\nThe body you need to pass with the DELETE method. Resources you want to delete. \u003cbr /\u003e\n\n**success** - `((AnyObject) -\u003e Void)` \u003cbr /\u003e\nSuccessful closure in case the request was successful. \u003cbr /\u003e\n\n**failure** -  `((NKHTTPRequestError) -\u003e Void)` \u003cbr /\u003e\nFailure Closure which notifies if any error has occured during the request. \u003cbr /\u003e\n\n\u003c!-- #### OAuth 2.0\n\nOr if you need OAuth 2.0 to use an API, that's also simple, just include the auth **consumer key** and **consumer secret** when you perform a request:\n\n```swift\nNKHTTPRequest.GET(\n  \"https://hacker-news.firebaseio.com/v0/item/11245652.json\",\n  auth: NKOauth(consumerKey: \"consumerKey\", consumerSecret: \"consumerSecret\"),\n  params: [\"print\": \"pretty\"],\n  success: { data in\n      var item: NKEItem?\n      item \u003c-- data\n  },\n  failure: { error in\n      print(error.message)\n  })\n``` --\u003e\n\n#### Cancel HTTP Requests\n\nThere are error and internet availability checking implemented in the framework, but you can simply cancel any task you want if its needed:\n\n```swift\nlet dataTask = NKHTTPRequest.GET(\n  \"https://hacker-news.firebaseio.com/v0/item/11245652.json\",\n  params: [\"print\": \"pretty\"],\n  success: { data in\n\n  },\n  failure: { error in\n    print(error.message)\n})\n\ndataTask?.cancel()\n```\n\n### Parsing\n\nSimple use of parsing can be seen above. There are more advanced options to use\n\n#### Assigning default values\n\n```swift\nstruct NKItem: Deserializable {\n    var id = 0\n    var username = \"\"\n\n    init(data: [String : AnyObject]) {\n        id \u003c-- data[\"id\"]\n        username \u003c-- data[\"by\"]\n    }\n}\n```\n\n#### NSURL Deserialization\n\n```swift\nlet profileImage: NSURL?\nprofileImage \u003c-- \"https://example.com/images/profile_normal.png\"\n```\n\n#### NSDate Deserialization\n\n```swift\nlet date: NSDate?\ndate \u003c-- 1414172803 // timestamp to NSDate deserialization\n```\n\n#### Nested JSON\n\nLet's consider a the truncated version of the Twitter API response:\n\n[![Run in Postman](https://run.pstmn.io/button.svg)](https://www.getpostman.com/run-collection/aa59a52596f959def779)\n\n```json\n{\n  \"text\":\"Aggressive Ponytail #freebandnames\",\n  \"retweet_count\": 2,\n  \"user\":{  \n      \"name\":\"Sean Cummings\",\n      \"location\":\"LA, CA\",\n      \"verified\":false,\n      \"screen_name\":\"sean_cummings\"\n  }\n}\n```\n\nWhere you can just simply create a User and a Tweet structure with a user instance inside:\n\n```swift\nstruct NKTwitterUser: Deserializable {\n    var name = \"\"\n    var location = \"\"\n    var verified = false\n    var screenName = \"\"\n\n    init(data: [String : AnyObject]) {\n        name \u003c-- data[\"name\"]\n        location \u003c-- data[\"location\"]\n        verified \u003c-- data[\"verified\"]\n        screenName \u003c-- data[\"screen_name\"]\n    }\n}\n```\n\n```swift\nstruct NKTweet: Deserializable {\n    var text = \"\"\n    var retweetCount = 0\n    var user: NKTwitterUser?\n\n    init(data: [String : AnyObject]) {\n        text \u003c-- data[\"text\"]\n        retweetCount \u003c-- data[\"retweet_count\"]\n        user \u003c-- data[\"user\"]\n    }\n}\n```\n\nIt's that simple.\n\n## License\n\nNetworkKit is available under the MIT license. See the LICENSE file for more info.\nMIT ⓒ Alex Telek\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimex94%2FNetworkKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimex94%2FNetworkKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimex94%2FNetworkKit/lists"}