Swiftpack.co - Package - jdisho/TinyNetworking

Platform Swift 4.0 CocoaPods compatible

🌩 What is TinyNetworking

TinyNetworking is a simple network layer written in Swift.

  • Just a tiny wrapper around NSURLSession. 🌯
  • Supports CRUD methods (GET, POST, PUT, DELETE). ✌️
  • No external dependencies. 🎉
  • Works if you can determine how your data is being represented in JSON. 😇
  • Works for non JSON types as well.
  • Highly inspired by: https://talk.objc.io/episodes/S01E01-tiny-networking-library ❤️

🛠 Installation


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

pod 'TinyNetworking', '~> 0.3'
pod 'TinyNetworking/RxSwift', '~> 0.3' # for the RxSwift extentions

Then, run the following command:

$ pod install


Comming Soon

Swift Package Manager

Comming Soon


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.

👨🏻‍💻 Usage

📦 Resource

Resource is the core part of TinyNetworking and is generic over the result type.

Resource has five properties:

| Properties | | ----------|----------------- URL | URL of the endpoint Request method | by default GET, but required for PUT, POST, DELETE Parameters | only [String: String] Headers | [String: String] Decoding function | by default JSONDecoding, but required if you want to implement your decoding function.

Create Resource

Resource<BodyType, ResponseType>(url: URL(string: "..."))

Resouce contains two generic types, the type of the response that is expected and the type of the object that is part of the request body

🔗 GET resource:
Resource<Void,  ResponseType>(url: URL(string: "..."))

or simpler:

SimpleResource<ResponseType>(url: URL(string: "..."))
🔗 POST resource:
Resource<BodyType,  ResponseType>(url: URL(string: "..."), .post(*body*))
🔗 PUT resource:
Resource<BodyType,  ResponseType>(url: URL(string: "..."), .put(*body*))
🔗 DELETE resource:
Resource<BodyType,  ResponseType>(url: URL(string: "..."), .delete(*body*))

💄 Add parameters

var params: [String: String] = [:]
params["page"] = "1"
params["per_page"] = "10"
params["order_by"] = "popular"

SimpleResource<ResponseType>(url: URL(string: "..."), parameters: params)

🎩 Add header

let resource = SimpleResource<ResponseType>(url: URL(string: "..."))
resource.addHeader(key: "...", value: "...")

⚙️ Making and handling a request

The Resouce is useless until is part of a request:

import TinyNetworking

let tinyNetworking = TinyNetworking()

let resource = SimpleResource<ResponseType>(url: URL(string: "..."))

tinyNetworking.request(resource) { results in
  switch results {
    case let .success(response):
    case let .error(error):

🔥 Reactive Extensions

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


tinyNetworking.rx.request(resource).subscribe { event in
   switch event {
   case let .success(response):
   case let .error(error):

🐨 Author

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

🙏 Acknowledgements

This library is highly insipired on these amazing talks by Chris Eidhof and Florian Kugler at Swift Talk

📃 License

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


Stars: 8
Help us keep the lights on


Used By

Total: 0