Validation plugin for Moya.Result

Overview

MoyaResultValidate

CI Status Version License Platform

Why?

Sometimes we need to verify that the data returned by the server is reasonable, when Moya returns Result.success.

JSON returned by the server.

{
  "code": 2000,
  "msg": "success",
  "data": ...
}

Validate the JSON or XML or other type results. It seems not elegant.

provider.request(.baidu) { result in
    switch result {
    case let .success(response):
	if response["code"] == 2000 {
          /// success code
        } else {
          /// error code
        }
    case let .failure(error):
        break
    }
}

Use MoyaResultValidate

  1. Import.
import MoyaResultValidate
  1. Add plugin to Moya.
MoyaResultValidatePlugin()
  1. Let you already comply with the TargetType enum also implemented MoyaResultValidateable protocol.
extension RequestApi: MoyaResultValidateable {
    
    func isResultSuccess(response: Response) -> Bool {
        // Validation rules
    }
}

The it will work.Your request will look like this.

The Result.success(response) that does not match isResultSuccess will be transferred to Result.Failure.

You can use error.asValidateError to get Moya.Response.

provider.request(.baidu) { result in
    switch result {
    case let .success(response):
				// succees 
    case let .failure(error):
      	// You can use error.asValidateError get Moya.Response.
        error.asValidateError?.response
    }
}

Requirements

  • iOS 10.0 or later

Installation

MoyaResultValidate is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MoyaResultValidate'

License

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

You might also like...
Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift

EVReflection General information At this moment the master branch is tested with Swift 4.2 and 5.0 beta If you want to continue using EVReflection in

This package is meant to make http request of an easy way inspiren in the architecture of Moya package

NetworkAgent This package is meant to make http request of an easy way inspiren in the architecture of Moya package. This package is 100% free of depe

Reflection based (Dictionary, CKRecord, NSManagedObject, Realm, JSON and XML) object mapping with extensions for Alamofire and Moya with RxSwift or ReactiveSwift

EVReflection General information At this moment the master branch is tested with Swift 4.2 and 5.0 beta If you want to continue using EVReflection in

đŸ¯ Syntactic sugar for Moya

MoyaSugar Syntactic sugar for Moya. Why? Moya is an elegant network abstraction layer which abstracts API endpoints gracefully with enum. However, it

🧚 RxSwift + Moya + HandyJSON + Plugins.

RxNetworks 🧚 . RxSwift + Moya + HandyJSON + Plugins. 👒 👒 👒 English | įŽ€äŊ“中文 This is a set of infrastructure based on RxSwift + Moya MoyaNetwork This

GitTime is GitHub Tracking App. Using ReactorKit, RxSwift, Moya.
GitTime is GitHub Tracking App. Using ReactorKit, RxSwift, Moya.

GitTime Feature Activity: GitHub Contributions graph & Event lists Trending: Trending Repositories & Developers Buddys: Show your buddy's contribution

Xcode-streamdeck-plugin - A Stream Deck plugin for Xcode
Xcode-streamdeck-plugin - A Stream Deck plugin for Xcode

Stream Deck Xcode Plugin This repository contains a Stream Deck plugin to add so

Plugin-spell-timer - Spell Timer Plugin for Outlander

Spell Timer Plugin for Outlander This plugin provides variables for spells from

Cordova-plugin-saveimage - This plugin helps you save images

cordova-plugin-saveimage This plugin helps you save images on iOS/Android Instal

Swift-lint-plugin - A SwiftPM plugin that adds a linting command

SwiftLintPlugin This is a SwiftPM plugin that adds a lint command. SwiftPM plugi

RResultBuilder is DSL library based on Result Builder
RResultBuilder is DSL library based on Result Builder

RResultBuilder is DSL library based on Result Builder Features Requirements Installation Usage Screenshot Example Contribute Meta Feat

Apps for translating Braille document captured by iPhone camera, then send translation result to ITS's Braille printer for duplicating purpose (re-printing, copying braille document with no original text)

SCANDO iOS On my Final Project (Thesis) for my Bachelor degree, I made an apps that translate Braille Document, and send the translation result to the

An awesome Swift CSS DSL library using result builders.

An awesome Swift CSS DSL library using result builders.

An awesome Swift HTML DSL library using result builders.

SwiftHtml An awesome Swift HTML DSL library using result builders. let doc = Document(.html5) { Html { Head { Meta()

A result builder that allows to define shape building closures
A result builder that allows to define shape building closures

ShapeBuilder A result builder implementation that allows to define shape building closures and variables. Problem In SwiftUI, you can end up in a situ

A convenient class usable from UIKit view controller or SwiftUI to scan document & get UIImage or PDFDocument as result - Replacement of IRLDocumentScanner

Super easy SwiftUI & UKKit pakcage to scan: Images or PDF. It is also a replacement for IRLScannerViewController

īŖŋ Sample iOS App  - A collection of examples and patterns for Unit Testing, UI Testing, handling Result/Optionals, writing documentation
īŖŋ Sample iOS App - A collection of examples and patterns for Unit Testing, UI Testing, handling Result/Optionals, writing documentation

īŖŋ Sample iOS App - A collection of examples and patterns for Unit Testing, UI Testing, handling Result/Optionals, writing documentation, and more

A result builder for ViewModifiers

A result builder for ViewModifiers

Owner
Insect_QY
æ„ŋ逐月华æĩį…§å›
Insect_QY
RxValidator Easy to Use, Read, Extensible, Flexible Validation Checker.

RxValidator Easy to Use, Read, Extensible, Flexible Validation Checker. It can use without Rx. Requirements RxValidator is written in Swift 4.

GeumSang Yoo 153 Nov 17, 2022
Swift Validator is a rule-based validation library for Swift.

Swift Validator is a rule-based validation library for Swift. Core Concepts UITextField + [Rule] + (and optional error UILabel) go into

null 1.4k Dec 29, 2022
String (and more) validation for iOS

Swift Validators ?? String validation for iOS. Contents Installation Walkthrough Usage Available validators License ReactiveSwift + SwiftValidators Wa

George Kaimakas 241 Nov 13, 2022
Drop in user input validation for your iOS apps.

Validator Validator is a user input validation library written in Swift. It's comprehensive, designed for extension, and leaves the UI up to you. Here

Adam Waite 1.4k Dec 29, 2022
đŸšĻ Validation library depends on SwiftUI & Combine. Reactive and fully customizable.

?? Validation library depends on SwiftUI & Combine. Reactive and fully customizable.

Alexo 14 Dec 30, 2022
Input Validation Done Right. A Swift DSL for Validating User Input using Allow/Deny Rules

Valid Input Validation Done Right. Have you ever struggled with a website with strange password requirements. Especially those crazy weird ones where

Mathias Quintero 37 Nov 3, 2022
TupleResult - A micro library that easily converts tuple result into Swift.Result

TupleResult A micro library that easily converts c-style tuple result into Swift

Ernest SeongHo Hong 0 Jan 29, 2022
A result builder that build HTML parser and transform HTML elements to strongly-typed result, inspired by RegexBuilder.

HTMLParserBuilder A result builder that build HTML parser and transform HTML elements to strongly-typed result, inspired by RegexBuilder. Note: Captur

null 4 Aug 25, 2022
iOS validation framework with form validation support

ATGValidator ATGValidator is a validation framework written to address most common issues faced while verifying user input data. You can use it to val

null 51 Oct 19, 2022
iOS validation framework with form validation support

ATGValidator ATGValidator is a validation framework written to address most common issues faced while verifying user input data. You can use it to val

null 51 Oct 19, 2022