-
RxAlamofireSwift/RxSwift 2022. 10. 3. 00:01
책을 뒤져보다가 우연히 RxAlamofire 를 발견했다. (RxCommunity 프로젝트들 중 하나.)
Alamofire 는 iOS 진영에서 매우매우 많이 쓰는 API Request Framework 이다.
RxAlamofire 를 이용해 쓸 수 있는 단순한 형태의 함수들은 아래와 같은 것들이 있다.
// retrieve a request result as raw text RxAlamofire.string(method: HTTPMethod, url: URLConvertible)
// decoded json 을 return 하기 때문에, .map 을 이용해서 Type 을 바꿔주거나, // 또는 subscription 내에서 형변환을 시켜주면 된다. RxAlamofire.json(.get, stringURL)
// raw Data RxAlamofire.data(.get, stringURL)
//parameter 넣기. http://api.openweathermap.org/data/2.5/weather? q=London&APPID={APIKEY} RxAlamofire.json(.get, "http://api.openweathermap.org/data/2.5/weather", parameters: ["q": "London", "APPID": "{APIKEY}"]) // header 또한 위와 같이 dictionary type 으로 넣어주면 된다.
// validation and manipulation by processing the underlying DataRequest. let response = request(.get, stringURL) .validate(statusCode: 200 ..< 300) .validate(contentType: ["text/json"]) .json()
'Swift > RxSwift' 카테고리의 다른 글
ReactorKit 에서 API 활용하기 (0) 2022.10.15 ReactorKit 으로 로그인 페이지 만들기 (0) 2022.10.14 RxSwift Observable, Subjects and Relays (0) 2022.10.01 UITableView (with RxSwift) (2) 2022.09.30 Login Validation (simple..) RxSwift 구현 (0) 2022.09.29