Extract Node in IBM API Connect
The purpose of this document is to provide a Brief understanding of how to use Extract Policy and its implementation in API Flow.
The Extract Policy in IBM API Connect is a powerful tool used to extract specific data from incoming requests or outgoing responses and store it in context variables.
This enables developers to dynamically manipulate and utilize data within the API flow, providing flexibility and enhancing the API’s capabilities.
Key Features and Benefits:
Data Extraction: The Extract Policy allows for the extraction of data from various parts of an HTTP message, such as headers, query parameters, and the body. This can be particularly useful for extracting authentication tokens, IDs, or other relevant information needed for processing.
Context Variables: Once data is extracted, it can be stored in context variables. These variables can then be used later in the API assembly to make decisions, transform data, or modify headers. This makes the API more dynamic and adaptable to different scenarios.
JSON Path and XPath Support: The Extract Policy supports JSON Path and XPath expressions, allowing for precise extraction of data from JSON and XML payloads, respectively. This ensures that only the necessary data is extracted, reducing overhead and improving performance.
Ease of Use: Implementing the Extract Policy is straightforward within the IBM API Connect designer interface. Developers can drag and drop the Extract Policy into the API assembly flow and configure it using a simple and intuitive interface.
Enhanced Security: By extracting sensitive information, such as tokens or personal data, and storing it securely in context variables, the Extract Policy helps enhance the security of API operations. This data can be further processed or validated to ensure secure transactions.
Versatility: The Extract Policy can be used in various scenarios, such as logging, conditional routing, or enriching requests and responses with additional data. This versatility makes it an essential tool for developing robust and efficient APIs.
Implementation in API Flow:
Step 1: Create a Sample API with much-needed basic functionalities.
Step 2: Now go to the Assembly and drag parse and Extract policies to the flow.
Step 3: here the Parse policy is only used to form a proper structure that, if not required can be avoided in the flow.
Step 4: now open the extract policy and configure.
- By default, the root element is assigned to
"message.body"
. - In the capture field, we have to specify the JSONata expression to extract the value of the particular parameter.
- The transform field is to transform the captured value to use it further.
Test Cases:
Now test the API with multiple JSONata Expression.
- $substring($,0,8) – Capture the first 8 characters of the Parameter “Name”
- $substring($, -9) – captures last 9 characters of Parameter “Name”.