How to map the target endpoint URL parameters to the proxy url

arunk
New Member

I have a target endpoint in the below format. How do I map these target endpoint URL parameters to the proxy URL params. As the mobile parameter can change based on the request from user. How to account for this change and dynamically configure the proxy URL and target URL.

http://control.msg91.com/api/sendotp.php?template=&otp_length=&authkey=&message=&sender=&mobile=&otp...

1 6 4,332
6 REPLIES 6

@Arun Kadari

Your question is not clear. From what I gather, I presume you are trying to:

1. match the query parameters in the URL in your conditional flows

just match the proxy.pathsuffix

for example, if your desired API proxy URL is http://example.com/v1/api/otps?template=x&sender=y

Configure the basepath in your API Proxy Endpoint as "/v1/api". Then at runtime your proxy.pathsuffix will be "/otps". And you can use this Condition in the conditional flow.

<Condition>(proxy.pathsuffix MatchesPath "/otps") and (request.verb = "GET") </Condition>

should be able to match irrespective of the number of query parameters passed

2. pass the query parameters from the proxy URL to the backend target, Query parameters are passed to the target by default unless you modify the target.url. In that case you can use request.querystring to append to the target.url

Hi created a spec and proxy as shown in the below code with the base path as /generate_otp and target endpoint as http://control.msg91.com. As per the below spec the post request to the target end point is /api/sendotp.php.

How should construct my front end URL to pass the query parameters to the base path?

Is it basepath+path+queryparams?

# Example YAML to get you started quickly.
# Be aware that YAML has indentation based coping.
# Code completion support is available so start typing for available options.
swagger: '2.0'

# This is your document metadata
info:
  version: "0.0.1"
  title: Example Title
  description: |
    A brief description of the API.
    It can be multiple lines.

host:
  control.msg91.com

schemes:
  - http
  - https

# Describe your paths here
paths:
  /api/sendotp.php:
    post:
      summary: test
      description: test
      parameters:
        - in: query
          name: authkey
          type: string
        - in: query
          name: sender
          type: string
        - in: query
          name: mobile
          type: string
        - in: query
          name: message
          type: string
      responses:
        200:
          description: OK

arunk
New Member

Hi created a spec and proxy as shown in the below code with the base path as /generate_otp and target endpoint as http://control.msg91.com. As per the below spec the post request to the target end point is /api/sendotp.php.

How should construct my front end URL to pass the query parameters to the base path?

Is it basepath+path+queryparams?

# Example YAML to get you started quickly.
# Be aware that YAML has indentation based coping.
# Code completion support is available so start typing for available options.
swagger: '2.0'

# This is your document metadata
info:
  version: "0.0.1"
  title: Example Title
  description: |
    A brief description of the API.
    It can be multiple lines.

host:
  control.msg91.com

schemes:
  - http
  - https

# Describe your paths here
paths:
  /api/sendotp.php:
    post:
      summary: test
      description: test
      parameters:
        - in: query
          name: authkey
          type: string
        - in: query
          name: sender
          type: string
        - in: query
          name: mobile
          type: string
        - in: query
          name: message
          type: string
      responses:
        200:
          description: OK
    
  

Yes the endpoint will be <Virtualhost>/basepath/path? queryparameters

irfan
New Member

As with a non-proxy resource, you can set up a proxy resource with the HTTP proxy integration by using the API Gateway console, importing an OpenAPI definition file, or calling the API Gateway REST API directly. For detailed instructions about using the API Gateway console to configure a proxy resource with the HTTP integration, see Build an API with HTTP Proxy Integration.

The following OpenAPI definition file shows an example of an API with a proxy resource that is integrated with the PetStore website. https://www.smsala.com

{
   "openapi": "3.0.0",
   "info": {
      "version": "2016-09-12T23:19:28Z",
      "title": "PetStoreWithProxyResource"
   },
   "paths": {
      "/{proxy+}": {
         "x-amazon-apigateway-any-method": {
            "parameters": [
               {
                  "name": "proxy",
                  "in": "path",
                  "required": true,
                  "schema": {
                     "type": "string"
                  }
               }
            ],
            "responses": {},
            "x-amazon-apigateway-integration": {
               "responses": {
                  "default": {
                     "statusCode": "200"
                  }
               },
               "requestParameters": {
                  "integration.request.path.proxy": "method.request.path.proxy"
               },
               "uri": "http://petstore-demo-endpoint.execute-api.com/petstore/{proxy}",
               "passthroughBehavior": "when_no_match",
               "httpMethod": "ANY",
               "cacheNamespace": "rbftud",
               "cacheKeyParameters": [
                  "method.request.path.proxy"
               ],
               "type": "http_proxy"
            }
         }
      }
   },
   "servers": [
      {
         "url": "https://4z9giyi2c1.execute-api.us-east-1.amazonaws.com/{basePath}",
         "variables": {
            "basePath": {
              "default": "/test"
            }
         }
      }
   ]
}

Not applicable

You can get all the request query parameters in the path suffix, then after you can use java script policy or extract variable policy to get all the query parameters, if you want to frame those in different parts then use assign message policy after that to set in the query parameters. Generally the request query sub-string automatically gets copied for the target .