If you are new to web service interfaces, first review HTTP Response Structure for an overview of what information you can typically find in an HTTP response.
Example: Queried a web service from Building HTTP Requests
...
We’ve covered how Building HTTP Requests. Now let’s take the resulting response from our request and break down strategies for handling HTTP responses.
The way you handle HTTP responses will depend on the API your working with and your interface requirements, however there are fundamental concepts to help you build your logic to handle your unique responses. Here is a simple example:
...
Expand | ||
---|---|---|
| ||
Using if statements you can apply conditional logic, depending on the success value, and branch your handling accordingly. |
Expand | ||
---|---|---|
| ||
Depending on the data type and format of the response, you can capture additional information, such as the data you fetched, success or error messages. Typically a response will either be in JSON or XML format:
|
Expand | ||
---|---|---|
| ||
HTTP status codes provide valuable information about the outcome of the request, and based on these codes, different actions can be taken, such as further retries or error handling. |
conditional logic to handle status codes and parse response
...
queue successful payload for downstream processing
parse error messages
...
Here we are using Arithmetic Operators to capture all possible 2XX status codes.
|