You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
« Previous
Version 8
Next »
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.
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:
Requests using retry.call return a success parameter you can use to frame your response handling
retry.call
from the Retry Library returns a success parameter, which you can use as the start of your framework to check if the HTTP request was successful.
Using if statements you can apply conditional logic, depending on the success value, and branch your handling accordingly.
Parse the response data
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:
For JSON: json.parse{}
For XML: xml.parse{}
Use HTTP response status codes to handle different outcomes
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.
Here we are using Arithmetic Operators to capture all possible 2XX status codes.
If a 2XX code is returned, we are treating it as a success and returning the response message. This is typically when you would queue or perform any additional processing on the data.
If a code outside of the 2XX series is returned, we are logging an error. At this stage is when you have the flexibility to handle the outcome as required - wether that means logging an error to trigger a notification for your team or retrying the original request.