Contents

shial4/slazekit

SLazeKit is an easy to use Swift restful collection of extensions and classes. Don't spend hours writing your code to map your rest api request into models and coredata serialization. Stop wasting your time!

πŸ”§ Installation

CocoaPods:

Add the line pod "SLazeKit" to your Podfile

Carthage:

Add the line github "shial4/SLazeKit" to your Cartfile

Manual:

Clone the repo and drag the folder SLazeKit into your Xcode project.

Swift Package Manager:

Add the line .package(url: "https://github.com/shial4/SLazeKit.git", from: "0.2.1"), to your Package.swift

Swift Package Manager in your iOS Project: This project demonstrates a working method for using Swift Package Manager (SPM) to manage the dependencies of an iOS project.

<a href="https://github.com/j-channings/swift-package-manager-ios">Example of how to use SPM v4 to manage iOS dependencies</a>

πŸ’Š Usage

For positive experience, you should configure SLazeKit at first.

SLazeKit in default configuration uses Default class which conforms to LazeConfiguration protocol. I do recommand extend Default configuration. Moreover , If you have more then one API in your project. You can create as many as needed configurations schemes by creating your own object which do conform to LazeConfiguration protocol.

import SLazeKit

extension Default {
    //Provide base path for your API requests.
    open class var basePath: String? { return "www.yourdomain.com" }
    //Additional you can set port for your requests.
    open class var basePort: Int? { return 8040  }
    //You can provide your own instance of JSONDecoder.
    open class var decoder: JSONDecoder { return JSONDecoder() }
    //You can customize instance of URLSession in here.
    open class var urlSession: URLSession { return URLSession.shared }
    
    //If you feel like to set header dor requests do it in here.
    open class func setup(_ request: URLRequest) -> URLRequest {
        var request: URLRequest = request
        request.setValue("Your token", forHTTPHeaderField: "X-Access-Token")
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        return request
    }
    //If you feel like to monitor response. You can do it in here.
    open class func handle(_ response: HTTPURLResponse?) {
        if response?.statusCode == 401 {
            Client.logout()
        }
    }
    
    /// Method dedicated to be use for synchronize object into persisten store
    ///
    /// - Parameter obj: encoded object
    /// - Throws: error occured during the process
    open static func synchronize(_ obj: Any) {}
}

⭐ Contributing

Be welcome to contribute to this project! :)

❓ Questions

Just create an issue on GitHub.

πŸ“ License

This project was released under the MIT license.

Package Metadata

Repository: shial4/slazekit

Default branch: master

README: README.md