Created
October 21, 2015 07:24
-
-
Save rizumita/ba45f9ee6f039ae2c09b to your computer and use it in GitHub Desktop.
protocolで組み上げるRESTクライアントライブラリ書いてる。 #swift #CodePiece
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol TestResourceType: JRResourceType { | |
typealias ServiceType = TestService | |
} | |
struct TestService: JRServiceType { | |
static let baseURL: NSURL? = NSURL(string: "https://example.com/api") | |
struct UsersResource: TestResourceType, JRPaginate { | |
static let path: JRPathType = "/users" | |
static var pageSerializer = JSONPageSerializer(contentsDecoder: JSONDecoder(keyPath: "users") { try decodeArray($0) as [User] }, paginationDecoder: JSONPaginationDecoder(keyPath: "pagination") { try decode($0) as Pagination }) | |
} | |
struct UserResource: TestResourceType, JRGet, JRPost { | |
static let getSerializer = JSONSerializer(contentsDecoder: JSONDecoder { try decode($0) as User }) | |
static let postSerializer = JSONSerializer(contentsDecoder: JSONDecoder { try decode($0) as User }) | |
static let path: JRPathType = "/user/:id" | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment