{"id":15037222,"url":"https://github.com/nil-biribiri/nilnetzwerk","last_synced_at":"2026-01-02T04:31:22.748Z","repository":{"id":62449051,"uuid":"140515851","full_name":"nil-biribiri/NilNetzwerk","owner":"nil-biribiri","description":"A super-lightweight network client library.","archived":false,"fork":false,"pushed_at":"2018-09-18T05:17:40.000Z","size":97,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-21T09:40:38.911Z","etag":null,"topics":["cocoapods","httpurlresponse","network","networking","response","swift3","swift4-1","urlrequest","urlsession","xcode"],"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/nil-biribiri.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":"2018-07-11T03:19:11.000Z","updated_at":"2020-02-26T03:23:15.000Z","dependencies_parsed_at":"2022-11-01T23:17:41.068Z","dependency_job_id":null,"html_url":"https://github.com/nil-biribiri/NilNetzwerk","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nil-biribiri%2FNilNetzwerk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nil-biribiri%2FNilNetzwerk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nil-biribiri%2FNilNetzwerk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nil-biribiri%2FNilNetzwerk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nil-biribiri","download_url":"https://codeload.github.com/nil-biribiri/NilNetzwerk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243402652,"owners_count":20285268,"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":["cocoapods","httpurlresponse","network","networking","response","swift3","swift4-1","urlrequest","urlsession","xcode"],"created_at":"2024-09-24T20:33:51.294Z","updated_at":"2026-01-02T04:31:22.691Z","avatar_url":"https://github.com/nil-biribiri.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NilNetzwerk\n\n[![CI Status](https://img.shields.io/travis/nilc.nolan@gmail.com/NilNetzwerk.svg?style=flat)](https://travis-ci.org/nilc.nolan@gmail.com/NilNetzwerk)\n[![Version](https://img.shields.io/cocoapods/v/NilNetzwerk.svg?style=flat)](https://cocoapods.org/pods/NilNetzwerk)\n[![License](https://img.shields.io/cocoapods/l/NilNetzwerk.svg?style=flat)](https://cocoapods.org/pods/NilNetzwerk)\n[![Platform](https://img.shields.io/cocoapods/p/NilNetzwerk.svg?style=flat)](https://cocoapods.org/pods/NilNetzwerk)\n\nA super-lightweight network client library. Heavily inspired by Moya, Alamofire.\n\n  **What you can do:**\n  \n  - [x] Making synchronous, asynchronous request.\n  - [x] Making chain synchronous request in background thread.\n  - [x] Create custom network client.\n  - [x] Build request separately.\n  - [x] Intercept, mutate request before execute.\n  - [x] Handle unauthorized request (Refresh token).\n  - [x] Basic auth (Oauth).\n  - [x] Add JSON support.\n  - [x] Network logger.\n  \n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n - iOS 9.3+\n - Xcode 8.3+\n - Swift 3.2+\n\n## Installation\n\nNilNetzwerk is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'NilNetzwerk'\n```\n\n## Usage \n\n\u003cdetails\u003e\u003csummary\u003eCreate request.\u003c/summary\u003e\n\u003cp\u003e\n \n  [Create a request](#create-a-request)\n  \n  [Create custom RequestGenerator](#create-custom-requestgenerator)\n  \n\u003c/p\u003e\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\u003csummary\u003eExecute request\u003c/summary\u003e\n\u003cp\u003e\n \n  [Making a simple get request](#making-a-simple-get-request)\n \n  [Making asynchronous request](#making-asynchronous-request)\n  \n  [Making synchronous request](#making-synchronous-request) \n  \n  [Making chain synchronous request in background thread](#making-chain-synchronous-request-in-background-thread) \n  \n\u003c/p\u003e\n\u003c/details\u003e\n\u003cp\u003e\u003c/p\u003e\n\n\u003cdetails\u003e\u003csummary\u003eAdvance usage\u003c/summary\u003e\n\u003cp\u003e\n \n  [Create custom NetworkClient](#create-custom-networkclient)\n\n  [Adapter (intercept before execute request)](#adapter)\n \n  [Handle unauthorized (getting called if host return 401)](#handle-unauthorized)\n    \n\u003c/p\u003e\n\u003c/details\u003e\n\n  ### Making a simple get request\n  \n```swift\nimport NilNetzwerk\n\nNilNetzwerk.sharedInstance.get(url: URL(string: \"https://httpbin.org/get\")!) { (result: Result\u003cSimpleModel\u003e) in\n      switch result {\n      case .success(let response):\n        print(response)\n      case .failure(let error):\n        print(error)\n      }\n    }\n\nstruct SimpleModel: Codable {}\n```\n\n  ### Create a request \n  \nYou can create a request by implementing \"ServiceEndpoint\" protocol with any type (enum, struct, class).\n(enum is recommended)\n\n```swift\nimport NilNetzwerk\n\n// An instance of the request generator which prepares the HTTP request.\nstruct TestRequestGenerator: RequestGenerator {\n  func generateRequest(withMethod method: HTTPMethod) -\u003e MutableRequest {\n    return request(withMethod: method) |\u003e withJsonSupport\n  }\n}\n\n// Endpoints that you want to use.\nenum TestFetchEndPoint {\n  case testPost(name: String, job: String)\n}\n\n// Implementing ServiceEndpoint protocol\nextension TestFetchEndPoint: ServiceEndpoint {\n\n  // An instance of the request generator which prepares the HTTP request.\n  var requestGenerator: RequestGenerator {\n    return TestRequestGenerator()\n  }\n\n  // The parameters of the endpoint.\n  var parameters: Codable? {\n    switch self {\n    case .testPost(let name, let job):\n      return TestPostModel(name: name, job: job)\n    }\n  }\n\n  // The base url for the endpoint.\n  var baseURL: URL {\n    switch self {\n    case .testPost:\n      return URL(string: \"https://reqres.in/api\")!\n    }\n  }\n\n  // The required method.\n  var method: HTTPMethod {\n    switch self {\n    case .testPost:\n      return .POST\n    }\n  }\n\n  // The specific path of the endpoint.\n  var path: String {\n    switch self {\n    case .testPost:\n      return \"/users\"\n    }\n  }\n\n  // The query parameters which are added to the url.\n  var queryParameters: [String : String]? {\n    switch self {\n    case .testPost:\n      return nil\n    }\n  }\n  \n  // The parameters which are added to the header.\n  var headerParameters: [String : String]? {\n    switch self {\n    case .testPost:\n      return nil\n    }\n  }\n  \n}\n\nstruct TestPostModel: Codable {\n  let name: String\n  let job: String\n}\n```\n\n  ### Create custom RequestGenerator\n  \nYou can create custom RequestGenerator by implementing RequestGenerator protocol.\n(Json support, Basic auth)\n\n```swift \nstruct TestRequestGenerator: RequestGenerator {\n\n  func generateRequest(withMethod method: HTTPMethod) -\u003e MutableRequest {\n    return request(withMethod: method) |\u003e withJsonSupport |\u003e withBasicAuth\n  }\n  \n  var authUserName: String? {\n    return \"Auth UserName\"\n  }\n  \n  var authPassword: String? {\n    return \"Auth Password\"\n  }\n \n}\n```\n\n  ### Making asynchronous request \n\n```swift\nimport NilNetzwerk\n\nlet testRequest = Request(endpoint: TestFetchEndPoint.testPost(name: \"Nil\", job: \"iOS\"))\nNilNetzwerk.sharedInstance.executeRequest(request: testRequest) { (result: Result\u003cTestPostModel\u003e) in\n      switch result {\n      case .success(let response):\n        print(response)\n      case .failure(let error):\n        print(error)\n      }\n    }\n```\n\n  ### Making synchronous request \n\n```swift\nimport NilNetzwerk\n\nlet testRequest = Request(endpoint: TestFetchEndPoint.testPost(name: \"Nil\", job: \"iOS\"))\nlet result: Result\u003cTestPostModel\u003e = NilNetzwerk.sharedInstance.executeRequest(request: testRequest)\nswitch result {\ncase .success(let response):\n  print(response)\ncase .failure(let error):\n  print(error)\n``` \n\n  ### Making chain synchronous request in background thread\n\n```swift\nimport NilNetzwerk\n\nlet testRequest = Request(endpoint: TestFetchEndPoint.testPost(name: \"Nil\", job: \"iOS\"))\nDispatchQueue.global(qos: .background).async {\n  let result: Result\u003cTestPostModel\u003e =  NilNetzwerk.sharedInstance.executeRequest(request: request)\n  print(\"TestNetworkClient: \\(result.isSuccess)\")\n  let result2: Result\u003cTestPostModel\u003e =  NilNetzwerk.sharedInstance.executeRequest(request: request)\n  print(\"TestNetworkClient: \\(result.isSuccess) \u0026 \\(result2.isSuccess)\")\n}\n``` \n\n\n  ### Create custom NetworkClient\n  \nYou can use default network client by calling \"NilNetzwerk.sharedInstance\". However, if you want to create custom network client you can extend \"NilNetzwerk\" class then implement your own network client.\n\n```swift\nimport NilNetzwerk\n\nclass TestNetworkClient: NilNetzwerk {\n  static let shared = TestNetworkClient()\n\n  private let urlSession: URLSession = {\n    let configuration                           = URLSessionConfiguration.default\n    configuration.requestCachePolicy            = .reloadIgnoringLocalAndRemoteCacheData\n    configuration.timeoutIntervalForRequest     = 30\n    configuration.urlCache                      = nil\n    return URLSession(configuration: configuration)\n  }()\n\n  override init() {\n    super.init(urlSession: urlSession)\n    enableLog = true\n  }\n\n}\n```\n\n  #### Adapter \n\nIntercept method before execute request.\n\n```swift\nimport NilNetzwerk\n\nclass CustomNetworkClient: NilNetzwerk {\n\n  // intercept method \n  override func adapter(request: inout Request) {\n    \n  }\n\n}\n``` \n\n  #### Handle Unauthorized \n\nEvery request that return 401 (unauthorized) will be enqueue to property \"requestsToRetry\" then this method will be executed.\n\n```swift\nimport NilNetzwerk\n\nclass CustomNetworkClient: NilNetzwerk {\n\n  // Handle unauthorized method \n  override func handleUnauthorized(request: Request, completion: @escaping (Bool) -\u003e Result\u003cError\u003e?) {\n    // You can implement request, refresh token method here\n    \n    // This is a queue of unauthorized request, you can dequeue and execute request again.\n    let allRequestsToRetry = self.requestsToRetry\n  }\n\n}\n``` \n\n## Author\n\nNil-Biribiri, nilc.nolan@gmail.com\n\n## License\n\nNilNetzwerk is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnil-biribiri%2Fnilnetzwerk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnil-biribiri%2Fnilnetzwerk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnil-biribiri%2Fnilnetzwerk/lists"}