Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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
titleRequests 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.

Expand
titleParse 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{}

Expand
titleUse 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.

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.

  • 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.