TIBCO Mashery API Developer Blog

New Feature: Error Sets via Accept Headers

Many APIs today support multiple protocols and Mashery helps you manage that complexity.  Many REST APIs support multiple response formats, with XML and JSON being the most popular.  We released a small feature improvement that improves our handing of this type of multi response format API.  

We've added the ability to more easily configure your service to use http accept headers to control response formats.  While we had already supported a number of methods to request specific response formats, our Error Set selection logic previously required a custom adapter to respond to accept header directives.  We now support configuration via simple UI.

For example, in the call below, the application wishes to receive a JSON formatted response from the Acme API.

curl -v -H 'Accept: application/json' 'http://api.acme.com/v1/getList?api_key=fakekey' 

Your Mashery service needs to be configured to recognize the accept header of 'application/json' to have Mashery error responses (e.g. 403 Acount Inactive) return in JSON format.  To use this feature improvement, configure the Error Set Selection logic to respond to accept header directives like this:

  1. Create your error sets as usual in the "Errors" tab of the API Settings configuration screens
  2. On the endpoint you wish to configure for accept header based response formats, navigate to the "Endpoints->Properties" tab
  3. In the Errors Configuration area, select "Accept Header" from the "Call Requested Selection Logic" drop down.

  4. Configure the accept header values you wish to support in the "Call Requested Selection Location" text field.  The field accepts content types in name/value pairs separated by commas.  The format is 'contenttype=error set name'. 
    • Example: application/xml=xml, application/json=json
    • In this example, 'xml' and 'json' should be the names of the error sets you've created that respond with XML or JSON formats.

Now, when your partners request XML or JSON in their accept headers, the Mashery service will respond with appropriately formatted responses, all through simple configuration.