Latest 1.3.1
Homepage https://github.com/rogermolas/RMHttp
License MIT
Platforms ios 10.0
Authors

Build Status
Status
license
Platform
Version
Twitter

RMHttp Lightweight RESTful library for iOS and watchOS
RMHttp is a Lightweight REST library for iOS and watchOS.

Features

  • [x] Chainable Request
  • [x] URL / JSON Parameter Encoding
  • [x] HTTP Methods GET/POST/DELETE/PATCH/PUT based in RFC2616
  • [x] Custom Request Builder / HEADERS / PARAMETERS
  • [x] Dynamic Response Handler (JSONObject, JSONArray, String)
  • [x] Codable Support
    TODO:
  • [-] Support Upload/Download resource

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

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

pod 'RMHttp'

Installation

pod "RMHttp"

Run the following command in your Terminal

$ pod install

Usage

HTPP Methods

HTTP Methods are declared in public enum RMHttpMethod.

GET, POST , DELETE , PUT , PATCH

Parameter Encoding

Encoding are declared in public enum Encoding

URLEncoding
JSONEncoding

Serialization

JSONObject – a representation of Dictionary<String, Any>

{
    "data" : "value",
    "isBoolean" : true,
    "list": [
        "object1",
        "object2"
    ]
}

JSONArray – a representation of [Dictionary<String, Any>]

[
    { "data1" : "value1"},
    { "data2" : "value2"},
    { "data3" : "value3"},
]

String
Any String respresentation (e.g HTML String, XML String, Plain Text)

Building Request
let params = [
"string":"Ipsum",   // String
"number": 100,      // Number
"boolean":true      // Boolean
] as [String : Any]

let urlString = "https://httpbin.org/get"
let request = RMRequest(urlString, method: .GET(.URLEncoding), parameters: params, hearders: nil)
Chained Response Handlers
Expecting Array object Response
RMHttp.JSON(request: request) { (response:JSONArray?, error) in
    guard error == nil else {
        self.title = "Response Error"
        self.activity.stopAnimating()
        self.textView.text = "(err)"
        return
    }
    self.activity.stopAnimating()
    if let data = response {
        self.title = "Response Sucess"
        self.textView.text = "(data)"
    }
}
Expecting JSON object Response
RMHttp.JSON(request: request) { (response:JSONObject?, error) in
    guard error == nil else {
        self.title = "Response Error"
        self.activity.stopAnimating()
        self.textView.text = "(err)"
        return
    }
    self.activity.stopAnimating()
    if let data = response {
        self.title = "Response Sucess"
        self.textView.text = "(data)"
    }
}

Generic method that return HTTP response has parameter data that comply to RMHttpProtocol (e.g JSONObject, JSONArray, String, )

public class func JSON<T:RMHttpProtocol>(request: RMRequest, completionHandler: @escaping Handler<T>)

Author

rogermolas, [email protected]

License

The MIT License (MIT)

Copyright (c) 2018 Roger Molas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Latest podspec

{
    "name": "RMHttp",
    "version": "1.3.1",
    "summary": "Lightweight RESTful library for iOS and watchOS",
    "homepage": "https://github.com/rogermolas/RMHttp",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "rogermolas": "[email protected]"
    },
    "source": {
        "git": "https://github.com/rogermolas/RMHttp.git",
        "tag": "1.3.1"
    },
    "social_media_url": "https://twitter.com/roger_molas",
    "platforms": {
        "ios": "10.0"
    },
    "source_files": "RMHttp/Classes/*.swift"
}

Pin It on Pinterest

Share This