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

RMHttp Lightweight RESTful library for iOS and watchOS

Build Status
Status
license
Twitter

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)
    TODO:
  • [-] Codable Support
  • [-] Support Upload/Download resource

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 request = RMRequest(urlString: urlString,
method:RMHttpMethod.GET(Encoding.URLEncoding),
parameters: nil,
hearders: nil)
Chained Response Handlers
Expecting Array object Response
RMHttp.request(completionHandler: { (response: JSONArray?) in
    if let data = response {
        self.textView.text = "(data)"
    }
}, errorHandler: { (error) in
    if let err = error {
        self.textView.text = "(err)"
    }
}, request: request)
Expecting JSON object Response
RMHttp.request(completionHandler: { (response: JSONObject?) in
    if let data = response {
        self.textView.text = "(data)"
    }
}, errorHandler: { (error) in
    if let err = error {
        self.textView.text = "(err)"
    }
}, request: request)

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

public class func request<T:RMHttpProtocol>(urlRequest: RMRequest,
                            completionHandler: @escaping (_ data: T?) -> Swift.Void,
                            errorHandler: @escaping (_ error: RMError?) -> Swift.Void)

Latest podspec

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

Pin It on Pinterest

Share This