diff --git a/Content/SLazeKit.png b/Content/SLazeKit.png new file mode 100644 index 0000000..e6920f6 Binary files /dev/null and b/Content/SLazeKit.png differ diff --git a/README.md b/README.md index 7f717b7..ce0e964 100644 --- a/README.md +++ b/README.md @@ -89,12 +89,43 @@ extension SLazeKit { } ``` -**Model example** +**Flow** + +

+ +

+ +- 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. +```swift +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 creat new instance and fill `NSManagedObject` with response data. You can serialize your response to recive `CoreData` object on given context by: + +```swift +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](Tests/SLazeKitTests/Models/Object.swift) Advance [Model.swift](Tests/SLazeKitTests/Models/Model.swift) + ## ⭐ Contributing Be welcome to contribute to this project! :)