I know that testing API response time is mostly done using Server or Backend, but since I work for a single application, I need to also check the api response time from iOS End.
How can i do this? I read a few links saying it needs to be done with the start of a timer and a timer, and then find the response time for endTime - startTime , but that seems unacceptable.
I want to use Xcode (even if XCTest exists).
Here is my one of the APIs (I wrote the whole method of using web services in a separate class in the ApiManager class):
LoginVC :
let apiManager = ApiManager()
apiManager.delegate = self
apiManager.getUserInfoAPI()
ApiManager :
func getUserInfoAPI() {
let headers = [
"Accept" : "application/json",
"Content-Type" : "application/json",
]
AlamoFireSharedManagerInit()
Alamofire.request(HCConstants.URL, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: headers).responseJSON { response in
do{
if let error = response.result.error {
self.hideHud()
self.delegate?.APIFailureResponse(HCConstants.EXCEPTION_MESSAGES.SERVICE_FAILURE)
return
}
let responseValue = try JSONSerialization.jsonObject(with: response.data!, options: JSONSerialization.ReadingOptions()) as! Dictionary<String, AnyObject>
print(responseValue)
if let mEmail = responseValue[HCConstants.Email] as? String {
UserDefaults.standard.setValue(mEmail, forKey: HCConstants. mEmail)
}
self.hideHud()
if let _ = responseValue["info"] as? String {
self.delegate?.apiSuccessResponse(responseValue)
}
else {
self.delegate?.APIFailureResponse(responseValue["message"] as? String ?? HCConstants.EXCEPTION_MESSAGES.SERVICE_FAILURE)
}
} catch {print("Exception is there "}
}
}