Monday, June 2, 2014

Handling 404 backend response

In REST API interactions its common to obtain and handle 404 response. The behaviour is used to support create or update scenario for a resources. Check if the resource exists, if it does update it using PUT otherwise create it using POST verb.

404 response from backend is treated as an error in Apigee and such a response results in execution of the fault flow instead of the response flow. The method of dealing with such a scenario is to use the success.codes property of target endpoint properties. Following is an example configuration of target end point to deal with 404 as a success response.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="billing">
    <HTTPTargetConnection>
        <LoadBalancer>
            <Algorithm>RoundRobin</Algorithm>
            <RetryEnabled>true</RetryEnabled>
            <MaxFailures>10</MaxFailures>
            <Server name="BillingTarget">
                <IsEnabled>true</IsEnabled>
            </Server>
        </LoadBalancer>
        <Path>/user/{userid}/bill/{bill_id}</Path>
        <Properties>
            <Property name="success.codes">1XX,2XX,3XX,404</Property>
        </Properties>
        <HealthMonitor>
            <IsEnabled>true</IsEnabled>
            <IntervalInSec>5</IntervalInSec>
            <TCPMonitor>
                <ConnectTimeoutInSec>10</ConnectTimeoutInSec>
                <Port>443</Port>
            </TCPMonitor>
        </HealthMonitor>
    </HTTPTargetConnection>
</TargetEndpoint>

The success codes property above ensures that default behaviour is retained in addition to treating 404 as a success code. This configuration will ensure response flow of the proxy will be executed in case of 404 response too. Appropriate action can be take in the response flow by checking the status code value.

2 comments:

  1. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Apigee, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on Apigee. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us:
    Name : Arunkumar U
    Email : arun@maxmunus.com
    Skype id: training_maxmunus
    Contact No.-+91-9738507310
    Company Website –http://www.maxmunus.com



    ReplyDelete
  2. I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in Apigee , kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor led training on TECHNOLOGY. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
    For Demo Contact us.
    Sangita Mohanty
    MaxMunus
    E-mail: sangita@maxmunus.com
    Skype id: training_maxmunus
    Ph:(0) 9738075708 / 080 - 41103383
    http://www.maxmunus.com/



    ReplyDelete