API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  check header value and call respective backend

    Posted Thu June 20, 2024 06:35 AM

    Hi,

    I've a usecase where i need to check the incoming request header (example: domain) once that header values matches then we need to call the respective backend endpoint. Can you please help on how we can implement this logic using switch condition in api connect v10 ?

    Example

    incoming request header name is domain

    if domain = a, then call a endpoint

    domain = b, then call b endpoint

    domain = c, then call c endpoint

    Appreciate your help on this.. Thank you



    ------------------------------
    Raja Kumar
    ------------------------------


  • 2.  RE: check header value and call respective backend

    Posted Thu June 27, 2024 05:16 PM

    Hi Raja,
    In your switch policy conditions, assuming this is an API Gateway v2.0.0 switch policy, for each condition you can use request.headers.domain = 'x' where x is a | b | c.  Your rule for each conditional could be a separate invoke policy that hardcodes the backend target-url, or you could use a set variable in each rule that set some variable, call it endpoint-url, to the desired backend endpoint url, and then after the switch, you could have one invoke policy that simply uses that variable in the target-url property as $(endpoint-url).  Either way should work for you.

    Regards,
    Steve Linn



    ------------------------------
    Steve Linn
    Senior Consulting I/T Specialist
    IBM
    ------------------------------