All Projects β†’ jdisho β†’ Tinynetworking

jdisho / Tinynetworking

Licence: mit
🌩 Simple HTTP network abstraction layer written in Swift

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Tinynetworking

Cocoadebug
iOS Debugging Tool πŸš€
Stars: ✭ 3,769 (+2989.34%)
Mutual labels:  networking, cocoapods
Fire
πŸ”₯A delightful HTTP/HTTPS networking framework for iOS/macOS/watchOS/tvOS platforms written in Swift.
Stars: ✭ 243 (+99.18%)
Mutual labels:  networking, cocoapods
Networking
Easy HTTP Networking in Swift a NSURLSession wrapper with image caching support
Stars: ✭ 1,269 (+940.16%)
Mutual labels:  networking, cocoapods
Netfox
A lightweight, one line setup, iOS / OSX network debugging library! 🦊
Stars: ✭ 3,188 (+2513.11%)
Mutual labels:  networking, cocoapods
Restofire
Restofire is a protocol oriented networking client for Alamofire
Stars: ✭ 377 (+209.02%)
Mutual labels:  networking, cocoapods
Dknetworking
基于 AFNetworking + YYCache ηš„δΊŒζ¬‘ε°θ£…οΌŒζ”―ζŒηΌ“ε­˜η­–η•₯ηš„η½‘η»œθ―·ζ±‚ζ‘†ζžΆ
Stars: ✭ 41 (-66.39%)
Mutual labels:  networking, cocoapods
Alamofire
Elegant HTTP Networking in Swift
Stars: ✭ 36,896 (+30142.62%)
Mutual labels:  networking, cocoapods
Emspinnerbutton
UIButton sublcass with loading animation
Stars: ✭ 117 (-4.1%)
Mutual labels:  cocoapods
Rtp
A Go implementation of RTP
Stars: ✭ 120 (-1.64%)
Mutual labels:  networking
Pytun
Linux TUN/TAP wrapper for Python
Stars: ✭ 116 (-4.92%)
Mutual labels:  networking
P2p
P2P Cloud project allows users to build their private networks.
Stars: ✭ 116 (-4.92%)
Mutual labels:  networking
Netclient Ios
Versatile HTTP Networking in Swift
Stars: ✭ 117 (-4.1%)
Mutual labels:  networking
Carvel Kwt
Kubernetes Workstation Tools CLI
Stars: ✭ 119 (-2.46%)
Mutual labels:  networking
Ona
OpenNetAdmin IP Address Management (IPAM) system
Stars: ✭ 116 (-4.92%)
Mutual labels:  networking
Bettersegmentedcontrol
An easy to use, customizable replacement for UISegmentedControl & UISwitch.
Stars: ✭ 1,782 (+1360.66%)
Mutual labels:  cocoapods
Swiftloader
A simple and beautiful activity indicator written in Swift
Stars: ✭ 116 (-4.92%)
Mutual labels:  cocoapods
Rcalendarpicker
RCalendarPicker A date picker control, Calendar calendar control, select control, calendar, date selection, the clock selection control. ζ—₯εŽ†ζŽ§δ»Ά ,ζ—₯εŽ†ι€‰ζ‹©ζŽ§δ»ΆοΌŒζ—₯εŽ†οΌŒζ—₯ζœŸι€‰ζ‹©οΌŒζ—Άι’Ÿι€‰ζ‹©ζŽ§δ»Ά
Stars: ✭ 121 (-0.82%)
Mutual labels:  cocoapods
Ipv6tools
IPv6Tools is a robust modular framework that enables the ability to visually audit an IPv6 enabled network.
Stars: ✭ 120 (-1.64%)
Mutual labels:  networking
Sqift
Powerful Swift wrapper for SQLite
Stars: ✭ 119 (-2.46%)
Mutual labels:  cocoapods
Dddkit
360 video player for iOS written in swift - a subset of SceneKit that works
Stars: ✭ 118 (-3.28%)
Mutual labels:  cocoapods

🌩 TinyNetworking

Mac Twitter: @_disho

  • A simple network abstraction layer written in Swift.
  • A thin wrapper around NSURLSession.
  • Supports CRUD methods.
  • Compile-time checking for correct API endpoint accesses.
  • Combine extensions to the API.
  • (Optional) RxSwift extensions to the API.
  • Inspired by Moya.
  • No external dependencies.

πŸ›  Installation

CocoaPods

To integrate TinyNetworking into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'TinyNetworking'
    
#or
    
pod 'TinyNetworking/RxSwift' # for the RxSwift extentions

Then, run the following command:

$ pod install

Carthage

Coming Soon

Swift Package Manager

Add the following as a dependency to your Package.swift:

.package(url: "https://github.com/jdisho/TinyNetworking.git", .upToNextMajor(from: "4.0.0"))

Manually

If you prefer not to use any of the dependency managers, you can integrate TinyNetworking into your project manually, by downloading the source code and placing the files on your project directory.

πŸƒβ€β™€οΈ Getting started

Set up an enum with all of your API resources like the following:

enum Unsplash {
  case me
  case photo(id: String)
  case collection(id: String)
  case likePhoto(id: String)
  ...
}

Extend enum and confom to Resource protocol.

extension Unsplash: Resource {
  var baseURL: URL {
    return URL(string: "https://api.unsplash.com")!
  }
  
  var endpoint: Endpoint {
    switch self {
    case .me:
      return .get(path: "/me")
    case let .photo(id: id):
      return .get(path: "/photos/\(id)")
    case let .collection(id: id):
      return .get(path: "/collections/\(id)")
    case let .likePhoto(id: id):
      return .post(path: "/photos/\(id)/like")
    }
  }
 
  var task: Task {
    var params: [String: Any] = [:]
    return .requestWithParameters(params, encoding: URLEncoding())
  }
  
  var headers: [String: String] {
    return ["Authorization": "Bearer xxx"]
  }
  
  var cachePolicy: URLRequest.CachePolicy {
    return .useProtocolCachePolicy
  }
}

βš™οΈ Making and handling a request

import TinyNetworking

let tinyNetworking = TinyNetworking<Unsplash>()

tinyNetworking.request(.photo(id: "1234")) { result in
  switch result {
    case let .success(response):
      let photo = try? response.map(to: Photo.self)
      print(photo)
    case let .failure(error):
      print(error)
  }
}

πŸ”– Response

After making a request, TinyNetworking gives a result back in the form of Result<Response, TinyNetworkingError>, which has two cases to switch over. In case of success, a Response object is given, otherwise an error.

The Response object gives the possibility to use:

  • Raw data from the request.
  • The URLRequest object.
  • The HTTP response.
  • Debug description.
  • The JSON repdesentation of the data.
  • The pretty printed version of the data in a JSON format.
  • Method to map/decode the data to a decodable object. A decodable object, is an object that conforms to Codable (Decodable+Encodable) protocol.

🐍 Reactive Extensions

Reactive extensions are cool. TinyNetworking provides reactive extensions for Combine, RxSwift and soon for ReactiveSwift.

Combine

return tinyNetworking
     .requestPublisher(resource: .photo(id: id))
     .map(to: Photo.self)

RxSwift

return tinyNetworking.rx
     .request(resource: .photo(id: id))
     .map(to: Photo.self)

✨ Example

See Papr

πŸ‘€ Author

This tiny library is created with ❀️ by Joan Disho at QuickBird Studios

πŸ“ƒ License

TinyNetworking is released under an MIT license. See License.md for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].