Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harshvishu/goldendragon
iOS Networking Framework
https://github.com/harshvishu/goldendragon
Last synced: 3 days ago
JSON representation
iOS Networking Framework
- Host: GitHub
- URL: https://github.com/harshvishu/goldendragon
- Owner: harshvishu
- License: mit
- Created: 2019-04-20T17:19:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-02T12:48:27.000Z (over 4 years ago)
- Last Synced: 2024-10-13T14:06:56.928Z (about 1 month ago)
- Language: Swift
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GoldenDragon
iOS Networking Framework![Image of Yaktocat](https://images.unsplash.com/photo-1514122769628-b4b8c3429ca5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1500&h=847&q=80)
### How to use?
- Extend `EndPointType` protocol
- Subclass `Router` in order to make the network calls
- Use Codable protocols```
enum Api {
case search(query: String)
}extension Api: EndPointType {
public var host: String {
return "api.github.com"
}
public var scheme: String {
return "https"
}
public var path: String {
switch self {
case .search:
return "/search/repositories"
}
}
public var httpMethod: HTTPMethod {
switch self {
case .search:
return .get
}
}
public var task: HTTPTask {
switch self {
case .search(let query):
let params: Parameters = [
"q": query
]
return .requestParameters(bodyParameters: nil, bodyEncoding: .urlEncoding, urlParameters: params)
}
}
public var headers: HTTPHeaders? {
return nil
}
}
``````
private var router: Router = Router()
func testApi() {
let expect: Future = router.request(Api.search(query: "swift"))
expect.observe { result in
switch result {
case .success(let searchData):
print("\(searchData.totalCount) repositories found")
case .failure(let error):
print(error.localizedDescription)
}
}
}
``````
struct SearchResult: Codable {
let totalCount: Int
let items: [Item]
enum CodingKeys: String, CodingKey {
case totalCount = "total_count"
case items
}
}
struct Item: Codable {
let id: Int
let htmlURL: String
let description: String
enum CodingKeys: String, CodingKey {
case id
case htmlURL = "html_url"
case description
}
}