External endpoint

Use the External endpoint policy when you have an external endpoint exposed, which can be configured and invoked during any stage in API processing.

If a native API expects the request in a certain format and the client application sends the request in a different format, you can add a custom extension to modify the incoming request to the required format before sending it to the native API.

In IBM API Studio, this policy is identified by the kind HTTPInvoke.

Example of an External Endpoint policy:

kind: HTTPInvoke
apiVersion: api.ibm.com/v1
metadata:
  name: http_invoke
  version: 1
  namespace: sample
spec:
  condition: (${request.httpMethod} equals POST) or (${request.headers.name} notEquals ${request.payload.jsonPath[$.customer.name]})
   # other operators include Equals, Equals ignore case, Not equals, Not equals ignore case, Contains, Not Contains, Exists, Not Exists, IP Range, Greater Than, Lesser Than
  endpoint :
    $ref : external_endpoint:1.0  #Refer kind: HTTPEndpoint
  request_processing:
    transformations:
      set:
        - key: ${request.headers.h2}
          value: test4
        - key: ${request.query.q2}
          value: ${request.payload.jsonPath[$.customer.name]}
      setPayload:
        content-types:
          - application/json: |
                        {"empid" : "1"}
          - application/xml: | 
                        <a>a<a>
          - text/plain: |
                      sample text
        defaultContentType: application/json
        xsl:
          - feature:
              - name: http://javax.xml.XMLConstants/feature/secure-processing
                value: true
            $path: ./format.xsl
            content: sdsd
      remove:
        - ${request.query.q1}
        - ${request.path}
    useIncomingHeaders: true
  response_processing:
    transformations:
      set:
        - key: ${request.headers.h2}
          value: test4
        - key: ${request.query.q2}
          value: ${request.payload.jsonPath[$.customer.name]}
      copyEntireResponse: true
      abortAPIExecutionForFailure: true    
  namespaces:
      - prefix: ps1
        URI: http://test.com
      - prefix: ps2
        URI: http://test2.com
---
kind: HTTPEndpoint
apiVersion: api.ibm.com\v1
metadata:
  name: default_endpoint
  version:1.0
spec:
  url: http://test.com
  method: GET
  connectTimeout: 300
  readTimeout: 200
  sslConfig:
    keyStoreAlias: ""
    keyAlias: ""
    trustStoreAlias: ""
  serviceRegistryParameters:
    - name: ""
      value: ""
       

For the HTTPInvoke policy kind, configure these specifications:

Code view Form view Description
condition Conditions

Conditions are used to specify when the policy is run. You can add multiple conditions with logical operators. Provide the condition in the format: {set} operator {value} condition {set} operator {value}

You can configure the following conditions in the Conditions section:

  • Transform the requests that comply with all the configured conditions in the code view by using and, or in the form view by selecting the AND option.
  • Transform the requests that comply with any one configured condition in the code view by using or, or in the form view by selecting the OR option.

You can use the following operators in the code view and in the form view by using the Add condition button, which is optional.

  • Equals
  • Equals ignore case
  • Not equals
  • Not equals ignore case
  • Contains
  • Not Contains
  • Exists
  • Not Exists
  • IP Range
  • Greater Than
  • Lesser Than
endpoint External endpoint

Specifies the URI of the endpoint in the code view by referencing endpoint in the policy code. Provide a $ref value in the format $ref: <external endpoint name>: version.

In the form view, configure endpoint details using the Create new endpoint button.

request_processing Request transformation

Specifies the request processing parameters.

You can configure the following transformation fields for both setPayload and remove functions:

  • Set the payload content type in the code view by using setPayload and in the form view, use the Payload type field, which is an optional step.

    Configure the content type in the code view using content-types, and in the form view use the Payload type field, which is an optional step.

    These are the content types that can be configured:
    • application/jsonin the code view and json in the form view. Provide the payload in the Payload section.

    • application/xmlin the code view and xml in the form view. Provide the payload in the Payload section.

    • text/plainin the code view and text in the form view. Provide the payload in the Payload section.

  • Under xsl, you specify one or more transformation files that determine how the payload is modified before it’s sent or processed.

    In the form view, use the XSLT document section for this configuration.

    • $path. Specifies the location of the XSL transformation file. IBM API Studio reads the file from the given path and applies the defined transformation rules.
    • feature. Lists one or more transformation features as name-value pairs. The name must specify a valid feature, such as http://javax.xml.XMLConstants/feature/secure-processing, and the value must be set to true or false.

    You can include multiple XSL entries under setPayload to apply different transformations based on your configuration.

response_processing Response transformation

Specifies the response processing parameters.

  • Specify the response processing parameters in the code view by using response_processing, or in the form view using the Response transformation section.

    Configure the following details:
    • Complete response from the messaging extension is forwarded back to the client in the code view when you set the copyEntireResponse to true.

      In the form view, you can configure this by selecting the Copy entire response field, which is optional.

    • Specify if the API execution should be stopped in case of messaging extension invocation failure in the code view when you set the abortAPIExecutionForFailure to true.

      In the form view, you can configure this by selecting the Abort API execution in case of failure field, which is optional.

    • In the code view, configure the set function and add the required details as key and value.

      In the form view, use the Add parameter to specify the header, query, or path parameter by providing the Variable and Value.

  • Add or update a new header in the message configuration request in the code view by using set and configure the key and value.

    In the form view, use the Add parameter to specify the header, query, or path parameter by providing the Variable and Value.

namespaces Namespace

Configure the metadata for the message configuration request.

In the code view, under namespaces, configure the prefix and URI.

In the form view, use the Custom metadata extension tab to configure the metadata. Click the Add namespace button and specify the Namespace prefix and Namespace URL, which are both optional fields.

To configure the Endpoint, you can specify:

Code view Form view Description
kind: HTTPEndpoint N.A.

Defines the type of asset that is being configured.

spec Endpoint Denotes various asset properties that you can configure for the endpoint.

These are the endpoint specifications that can be configured:

  • Add the URL for the endpoint in the code view under URL, or in the form view under Endpoint URL, which is an optional field.
  • Add the method in the code view under method, or in the form view under Method, which is an optional field.
  • Add the HTTP connection timeout in seconds in the code view under connectTimeout, or in the form view under HTTP connection timeout, which is an optional field.
  • Add the read timeout in seconds in the code view under readTimeout, or in the form view under Read timeout, which is an optional field.
  • Specify the SSL configurations in the code view using sslConfig, or in the form view under the SSL configuration section.

    You can configure the following SSL details:
    • Add the keystore alias in the code view under keyStoreAlias, or in the form view under Keystore alias, which is an optional field.
    • Add the key alias in the code view under keyAlias, or in the form view under Key alias, which is an optional field.
    • Add the truststore alias in the code view under trustStoreAlias, or in the form view under Trustsstore alias, which is an optional field.
  • Add or update the path parameter in the message configuration request in the code view by using serviceRegistryParameters and configure the name and value.

    In the form view, under the Path parameters, use the Add parameter button to specify the Path parameter name and Path parameter value, which are optional fields.

  • url.
  • method. Specifies the available routing methods.
  • connectTimeout. Specifies the time interval (in seconds) after which a connection attempt times out.
  • readTimeout. Specifies the time interval (in seconds) after which a socket read attempt times out.
  • sslConfig. Configures keystore, key alias, and truststore for securing connections to native APIs.
    • keystoreAlias. Specifies the keystore alias that is configured in API Gateway. This value (along with the value of Client Certificate Alias) is used for conducting an SSL client authentication.
    • keyAlias. Specifies the alias for the private key, which must be stored in the keystore that the keystore alias specifies.
    • TruststoreAlias. Specifies the alias for the truststore that contains the list of CA certificates that API Gateway uses to validate the trust relationship with the native API.
  • serviceRegistryParameters. Specifies values that are used for constructing the discovery service URI.