Concept

HTTP Response Validation is the process of checking whether a network request was successful or failed.

It is done using the status code returned by the server.


Key Idea

Request sent
↓
Response received
↓
Check status code
↓
Success or Failure

HTTPURLResponse

The response from a request must be cast to:

HTTPURLResponse

Example:

guard let httpResponse = response as? HTTPURLResponse else { return }

This provides access to:

statusCode
headers

Status Codes

Status codes indicate the result of a request.

Success

200 → OK
201 → Created
204 → No Content