Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Jarvis

Platform Language License pod 1.3.1 Swift 4

TheMindStudios

Jarvis is a lightweight network abstraction layer, built on top of Alamofire. It can be used to dramatically simplify client-to-server communication.

Features

  • Generic, protocol-based implementation
  • Support for iOS/macOS/tvOS/watchOS/
  • Easy to work with MultipartFormData
  • Support Codable protocol in Swift 4
  • Ability to log Response

Overview

We designed Jarvis to be simple to use and also very easy to customize. After initial setup, using Jarvis is very straightforward:

api.getPosts(for: page) { response in
    switch response.result {
    case .success(let posts):
        print("Received Posts: \(posts)")
    case .failure(let error):
        print("Posts request failed, parsed error: \(error)")
    }
}

Usage

  1. Import Jarvis module to your APIClient class
import Jarvis
  1. Add implementation for RequestDataProvider protocol. RequestDataProvider has default implementation, so you can set just properties you need:
struct PostsListAPIClient {
    
    enum Route: RequestDataProvider {
        
        case get(page: Int)
        
        var method: HTTP.Method {
            return .get
        }
        
        var baseUrl: URLConvertible {
            
            return URL(string: "http://jsonplaceholder.typicode.com")!
        }
        
        var path: String {
            
            switch self {
            case .get:
                return "posts"
            }
        }
        
        var parameters: Parameters? {
            
            switch self {
            case .get(let page):
                return ["page": page]
            }
        }
    }
}
  1. Make you sure that you model support protocol Decodable
struct Post: Decodable {
    
    let id: Int
    let userId: Int
    let title: String
    let body: String
}
  1. Sending requests
func getPosts(for page: Int, completion: @escaping (_ response: Response<[Post], APIError>) -> Void) {
        
    let request = Route.get(page: page)
    Jarvis.request(request).responseDecodable(completion: completion)
}
  1. Handling response
api.getPosts(for: page) { response in
    switch response.result {
    case .success(let posts):
        print("Received Posts: \(posts)")
    case .failure(let error):
        print("Posts request failed, parsed error: \(error)")
    }
}

Podfile

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

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target 'TargetName' do
  pod 'Jarvis'
end

Then, run the following command:

$ pod install

License

Jarvis is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Releases

No releases published

Packages

No packages published

Languages