Latest | 3.1.1 |
---|---|
Homepage | https://github.com/mr-noone/http-cab |
License | MIT |
Platforms | ios 8.0 |
Authors |
HTTPCab – network framework for HTTP requests and REST.
Usage
Using Providers
for structure you requests:
enum ProfileRequests {
case getUserProfile(id: String)
case postUserPhoneNumber(phoneNumber: String)
}
Then you need to specify all data you need for requests:
extension ProfileRequests: Request {
var baseURL: String {
return "https://your.domain.com"
}
var path: String {
switch self {
case .getUserProfile,
.postUserPhoneNumber:
return "/user"
}
}
var method: Method {
switch self {
case .getUserProfile:
return .get
case .postUserPhoneNumber:
return .post
}
}
var parameters: [String: String]? {
switch self {
case .getUserProfile(id: let id):
return ["user_id": id]
case .postUserPhoneNumber:
return nil
}
}
var body: RequestBody? {
switch self {
case .getUserProfile:
return nil
case .postUserPhoneNumber(phoneNumber: let phoneNumber):
return JSONBody(["phone_number" : phoneNumber])
}
}
var headers: [String: String]? {
return nil
}
}
For usage you need to specify the Provider
that will handle this requests:
class YourProfileProvider: Provider {
let sessionManager: SessionManager = .default
func getUser(id: String) {
dataRequest {
ProfileRequests.getUserProfile(id: id)
}.response { data, response, error in {
//...
}
}
func updatePhoneNumber(phone: String) {
dataRequest {
ProfileRequests.postUserPhoneNumber(phoneNumber: phoneNumber)
}.response { data, response, error in {
//...
}
}
}
Request body types
JSONBody
PlistBody
FormURLBody
MultipartBody
JSONEncodableBody
PlistEncodableBody
StringBody
You can create a custom body type by implement RequestBody
protocol:
struct CustomBody: RequestBody {
var contentType: String
var bodyData: Data
}
License
MIT license. See the LICENSE file for details.
Latest podspec
{ "name": "HTTPCab", "version": "3.1.1", "summary": "HTTPCab - network framework for HTTP requests and REST.", "homepage": "https://github.com/mr-noone/http-cab", "license": { "type": "MIT", "file": "LICENSE" }, "authors": { "Aleksey Zgurskiy": "[email protected]" }, "platforms": { "ios": "8.0" }, "source": { "git": "https://github.com/mr-noone/http-cab.git", "tag": "3.1.1" }, "source_files": "HTTPCab/HTTPCab/**/*.{swift}", "swift_version": "4.2" }
Thu, 30 May 2019 10:49:06 +0000