Skip to content

mediassumani/ShazamLite

Repository files navigation

A dynamically built, yet simple to use Networking Library for iOS.

HitCount star this repo fork this repo Build Status

Why use ShazamLite?

  • Absract complex URLSession functionalities from developers.
  • Configure model Encoding and Decoding for developers.
  • Provide support for all HTTP Request types (GET, POST, PUT, PATCH, DELETE).
  • Graceful handle of common HTTP errors.
  • Dynamic and custom construction of request.
  • Custom handle of server responses.

Requirements

  • Swift 4.2+
  • Xcode 10.2+
  • iOS 10.0

Installation

  • For iOS 10.0+ projects with Cocoapods:

      pod 'ShazamLite' 

Quick start

NOTE: ShazamLite only has two powerfull methods:

* get : Use this for requests when getting data from an API. 
* set : Use this for for requests when you're sending data to an API.
  • Your Model - make sure it conforms to the Codable protocol.
  struct Todo: Codable {
    
      var userId: Int?
      var title: String?
      var completed: Bool?
  }
  • Request for decoding JSON of type dictionary. See example here.
import ShazamLite

// Initialize a Shazam instance with a url/endpoint/route.
var downloader = Shazam(withUrlString: "https://jsonplaceholder.typicode.com/todo/1")

// Parameters and headers are optional
downloader.get(parameters: nil, headers: nil) { (result: Result<Todo?, Error>) in

  switch result{
      case let .success(todo):
        print(todo.title)
        // Your data available!
                
      case let .failure(error):
        // Errors are customed in ShazamLite, print it to see what caused the failure             
   }
}
  • Request for decoding JSON of type array. See example here.
import ShazamLite

var downloader = Shazam(withUrlString: "https://jsonplaceholder.typicode.com/todos")

downloader.get(parameters: nil, headers: nil) { (result: Result<[Todo]?, Error>) in

  switch result{
      case let .success(data):
        // Your data available!
                
      case let .failure(error):
        // Errors are customed in ShazamLite, print it to see what caused the failure             
   }
}
  • Request for sending data to a server with POST method.
import ShazamLite


var todo = Todo(userId: 1, title: "Get Food from work", completed: true)
var encodedData = try! JSONEncoder().encode(todo)
var downloader = Shazam(withUrlString: "https://jsonplaceholder.typicode.com/todo/1")

downloader.set(parameters: nil, headers: nil, method: .post, body: encodedBody) { (result: Result<Bool?, Error>) in

  switch result{
      case let .success(data):
        // Your data available!
        
                
      case let .failure(error):
        // Errors are customed in ShazamLite, print it to see what caused the failure             
   }
}

Developer

Built With

  • Swift 4.2
  • Xcode 10.2
  • Cocoapods 1.7.5

License

ShazamLite is an Open-sourced project and under the MIT license. See the LICENSE file for more info.

About

An asynchronous Swift HTTP Library built on top of URLSession⚡️

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published