APIResource 0.2.1

APIResource 0.2.1

onemoon维护。



  • onemoon

🌈APIResource

什么是APIResource

APIResource是一个资源管理库。管理诸如HTTP方法(GET / POST...)或查询(?hello=world)等资源。重要的是

您可以使用这个库通过

所以请享受这个库,您的

安装

您可以通过CocoaPods获取APIResource。要安装它,只需在Podfile中添加以下行

pod 'APIResource'

特点

  • 使用urlString初始化APIResource
  • 使用ResourceBase初始化APIResource
  • APIResource创建URLRequest

感谢PostmanEcho API,我可以测试我的功能,并用XCTestClass编写它们。

空框是测试不足的功能。

使用方法

APIResource是这个库的核心。你可以通过urlString或者ResourceBase来创建它。

// urlString is like "http://hello.com/path?12=34"
let apiResource: APIResource = APIResource("https://postman-echo.com/get?foo1=bar1&foo2=bar2")
// conform ResourceBase 
enum PostmanEchoAPI {
    case getRequest
}
extension PostmanEchoAPI: ResourceBase {
    var host: String? {
        switch self {
        case .getRequest:
            return "https://postman-echo.com/"
        }
    }
    var path: String? {
        switch self {
        case .getRequest:
            return "/get"
        }
    }
    var queryString: String? {
        switch self {
        case .getRequest:
            return "?foo1=bar1&foo2=bar2"
        }
    }
}

let apiResource: APIResource = PostmanEchoAPI.getRequest.apiResource

受到启发于

Alamofire

Just

Moya

授权

APIResource遵从MIT授权。更多详情请参阅LICENSE文件。