Reputation: 4530
I want to make a post call using RxAlamofire it provides function requestJson which requires two parameters type get or post and url but there is no parameter to pass post json body how to do that following is my code
var components = URLComponents(string: url)!
components.setQueryItems(with: param)
let url = components.url!
print("\(url)")
RxAlamofire.requestJSON(.post, url)
.subscribe(onNext: { [weak self] (r, json) in
if let jsonResult = JSON(json) as? JSON {
if let cartResult = FoodCartResult(jsonResult) as? FoodCartResult {
self?.delegate?.showCart(cartresult: cartResult)
}
}
}, onError: { [weak self] (error) in
print(error.localizedDescription)
self?.delegate?.onError()
},onCompleted: {})
.disposed(by: disposeBag)
Upvotes: 1
Views: 414
Reputation: 607
Actually the other parameters are included in the definition of requestJson, they just have default parameters. So you can safely say:
RxAlamofire.requestJSON(.post,
url,
parameters: ["param1": "value1"],
encoding: JSONEncoding.default,
headers: nil)
Upvotes: 0