Skip to content

Instantly share code, notes, and snippets.

@LukaszDziwosz
Last active August 8, 2022 15:03
Show Gist options
  • Save LukaszDziwosz/e0b0c97ad8e7c805f1ed8fadc21f3b16 to your computer and use it in GitHub Desktop.
Save LukaszDziwosz/e0b0c97ad8e7c805f1ed8fadc21f3b16 to your computer and use it in GitHub Desktop.
GitHub Search Alamofire
import Foundation
import Combine
import Alamofire
protocol RepoAPIProtocol {
func getRepos(quary: String, perPage: Int, page: Int) -> AnyPublisher<Repos, AFError>
}
struct RepoAPI: RepoAPIProtocol {
func getRepos(quary: String, perPage: Int, page: Int) -> AnyPublisher<Repos, AFError> {
let url = URL(string: "https://api.github.com/search/repositories")!
let parameters = [
"q": quary,
"per_page": perPage,
"page": page,
] as [String : Any]
let headers: HTTPHeaders = [
"Accept": "application/json"
]
return AF.request(url,
method: .get,
parameters: parameters,
headers: headers
)
.validate()
.publishDecodable(type: Repos.self)
.value()
.receive(on: DispatchQueue.main)
.eraseToAnyPublisher()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment