All Projects → shial4 → SLazeKit

shial4 / SLazeKit

Licence: MIT license
SLazeKit is a framework providing models mapper and CoreData serializer for RESTful resources.

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to SLazeKit

tinyweb
Simple and lightweight HTTP async server for micropython
Stars: ✭ 182 (+691.3%)
Mutual labels:  restful
RentHouseWeb
使用 go+docker+go-micro微服务框架开发的租房网系统,符合RESTful架构风格。
Stars: ✭ 28 (+21.74%)
Mutual labels:  restful
bdd-for-all
Flexible and easy to use library to enable your behavorial driven development (BDD) teams to easily collaborate while promoting automation, transparency and reporting.
Stars: ✭ 42 (+82.61%)
Mutual labels:  restful
nestjs-starter
🚀 Nest framework starter
Stars: ✭ 30 (+30.43%)
Mutual labels:  restful
protean
Evolve your RESTful API's and Web Services
Stars: ✭ 31 (+34.78%)
Mutual labels:  restful
restful-services-in-pyramid
RESTful / HTTP services in Pyramid and Python course handout materials
Stars: ✭ 56 (+143.48%)
Mutual labels:  restful
redap
HTTP-to-LDAP Gateway
Stars: ✭ 27 (+17.39%)
Mutual labels:  restful
BlobHelper
BlobHelper is a common, consistent storage interface for Microsoft Azure, Amazon S3, Komodo, Kvpbase, and local filesystem written in C#.
Stars: ✭ 23 (+0%)
Mutual labels:  restful
podcatcher
Podcast App
Stars: ✭ 21 (-8.7%)
Mutual labels:  coredata
angular6-httpclient-example
Angular 6 HttpClient: Consume RESTful API Example
Stars: ✭ 38 (+65.22%)
Mutual labels:  restful
Project17-C-Map
Map SDK를 활용한 POI Clustering Interaction Dev.
Stars: ✭ 41 (+78.26%)
Mutual labels:  coredata
iOS-Developer-Nanodegree
Learn how to program apps for the iPhone and iPad
Stars: ✭ 20 (-13.04%)
Mutual labels:  coredata
TMLPersistentContainer
Shortest-path multi-step Core Data migrations in Swift
Stars: ✭ 15 (-34.78%)
Mutual labels:  coredata
grapevine
Fast, unopinionated, embeddable, minimalist web framework for .NET
Stars: ✭ 72 (+213.04%)
Mutual labels:  restful
BoxFeed
News App 📱 built to demonstrate the use of SwiftUI 3 features, Async/Await, CoreData and MVVM architecture pattern.
Stars: ✭ 112 (+386.96%)
Mutual labels:  coredata
moyu
基于 Vue 和 Electron 的在线协同api接口管理工具。接口文档管理工具、接口工具、接口文档、api文档、api工具、快乐摸鱼
Stars: ✭ 300 (+1204.35%)
Mutual labels:  restful
express-rest-api
🍺 RESTful API sample in Express, Mongoose and ES6.
Stars: ✭ 28 (+21.74%)
Mutual labels:  restful
Spring-Boot-2
Spring Boot 2.x examples
Stars: ✭ 33 (+43.48%)
Mutual labels:  restful
Relaxation
Relaxation is a REST framework for ColdFusion that helps you build a REST API. And then it get's the heck out of your way.
Stars: ✭ 22 (-4.35%)
Mutual labels:  restful
dubai
迪拜后台系统框架:基于Springside、Mysql、Bootstrap2的后台系统框架,旨在为繁杂的各种业务流程提供一个界面简约、操作高效、运行稳定、容易集成和横向扩展的开发基础框架及规范。
Stars: ✭ 45 (+95.65%)
Mutual labels:  restful

SLazeKit

Language License CocoaPods Carthage

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!

SLazeKit allows you:

  • map your models by Codable protocol
  • serialize CoreData models from API response with SLazeCoreData or any other extension
  • fast and simple extend your models with API & CoreData

  • This request will use default configuration scheme.
  • The type ResponseModel is a result object type for result callback argument. If you want to decode array you simple execute method on [ResponseModel] type.
  • The error indicates why the request failed, or nil if the request was successful. it include EntityMaping errors, url preparation error and so on. If a response from the server is received, regardless of whether the request completes successfully or fails, the response parameter contains that information.
  • The response provides tuple with HTTPURLResponse object and the data returned by the server.
  • The request handler is executed on the URLSession delegate queue.
class func getRequest(for modelId: String, success: @escaping ((Model?) ->()), failure: (() ->())? = nil) throws {
    let _ = ResponseModel.get(path: PathPattern.model.patternToPath(with: ["modelId":modelId])) { (response, result, error) in
    guard response?.urlResponse?.statusCode == 200 && error == nil else {
        failure?()
        return
    }
    success(try result?.serialized(SLazeKit.newBackgroundContext()) as? Model)
    }
}

If ResponseModel conforms to EntityMapping protocol it will be synchronize with CoreData. That means if mode object already exist it will update it or create new instance and fill NSManagedObject with response data. You can serialize your response to receive CoreData object on given context by:

try result?.serialized(NSManagedObjectContext) as? Model)

Calling this method simple query NSManagedObject which was synchronize before by given object id.

Models example

Simple Object.swift Advance Model.swift

In case of any other configuration you can use Laze

//Laze<C: LazeConfiguration, D: Decodable>
Laze<Default, ResponseModel>.get( // Default configuration, result in ResponseModel model
SLazeKit<Default>.get( // Default configuration, no result model
ResponseModel.get( // Default configuration, result in ResponseModel model

🔧 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.

Example of how to use SPM v4 to manage iOS dependencies

💊 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.

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].