I am trying to handle a response made through Alamofire and I am trying to decode an empty response. The documentation states that for .responseDecodable "no empty responses unless allowed by the emptyResponseMethods and emptyResponseCodes." I am not sure what emptyResponseMethods mean but this is what I have implemented so far.
struct EmptyResponse: Codable {}
AF.request(self.baseURL+route, method: method, parameters: body, encoder: parameterEncoder, headers: httpHeaders)
.responseDecodable(of: successType, decoder: decoder, emptyResponseCodes: [204, 205]) { (response) in
print("DEBUG: NetworkManager.responseDecodable \(response)")
guard let success = response.value else { return }
completionHandler(success)
}
After I made a server request, the response is an HTTP 204 Empty Response.
I have another layer of abstraction for the variables you see here, but everything works out and I am focused on the .responseDecodable. I assume that if the successType is of EmptyResponse and with the emptyResponseCodes, I would be able to use .responseDecodable. It's not clear at all what the decoded response would be based on the documentation. I know that .responseData returns .nil.