[OIC] How to create REST Integration with Pagination in Oracle Integration Cloud?

 

 

Below are the few benefits of implementing pagination in your OIC REST integrations:

Improve Performance - Pagination allows you to limit the amount of data returned in each request, which can significantly improve performance, especially when dealing with large datasets. By retrieving data in smaller chunks, you reduce the load on both the client and server sides, making the integration more efficient. 


Resource Management - Large datasets can consume a significant amount of system resources, such as memory and network bandwidth. Pagination helps in managing these resources more effectively by fetching only the required subset of data at a time, thus preventing resource exhaustion.


Avoiding Timeout Issues: Retrieving large amounts of data in a single request can lead to timeout issues, especially in environments with strict request/response time limits. Pagination ensures that each request only fetches a manageable amount of data, reducing the likelihood of timeouts.


Scalability: Pagination allows integrations to scale more effectively. As the dataset grows, pagination ensures that the integration remains responsive and efficient by fetching data in smaller, manageable chunks.


Reduced Data Transfer Costs: In scenarios where data transfer costs are a concern (e.g., in cloud environments where outbound data transfer is billed), pagination helps reduce costs by limiting the amount of data transferred in each request.

 

This post will show how to create REST Integration with Pagination in Oracle Integration Cloud.

 

Suppose you integration is returning the data in following JSON format:

 

{
    "items": [
        {
            "id": 1,
            "name": "Leanne Graham",
            "username": "Bret",
            "email": "Sincere@april.biz",
            "website": "hildegard.org"
        }
    ],
"status": "Success",
"message": "Data fetched successfully"
}
 
 
Now, to implement pagination you have to add few additional fields in the response payload:
 
{
    "count":3,
    "hasMore":true,
    "limit":10,
    "offset":0,
    "items": [
        {
            "id": 1,
            "name": "Leanne Graham",
            "username": "Bret",
            "email": "Sincere@april.biz",
            "website": "hildegard.org"
        }
    ],
"status": "Success",
"message": "Data fetched successfully"
}
 
 
Also, add two query parameters in REST Trigger "limit" and "offset"
 
Suppose, previously you had used DB adapter with the below query for your integration:
 
SELECT
    id
    ,name
    ,username
    ,email
    ,website
FROM
    employees
 
 
Now just write the below procedure which will return the data and other attributes.
 
CREATE OR REPLACE PACKAGE BODY EMP_DATA_PKG
   
    /* This Procedure is invoked from OIC returns the paginated data*/
    PROCEDURE get_data(
        p_in_limit                  IN      NUMBER DEFAULT 0,
        p_in_offset                 IN      NUMBER DEFAULT 25,
        p_out_has_more              OUT     NUMBER,
        p_out_count                 OUT     NUMBER,
        p_out_status                OUT     VARCHAR2,
        p_out_message               OUT     VARCHAR2,
        p_out_data                  OUT     SYS_REFCURSOR          
    )
    AS
       
    BEGIN
   
        --Get total row count
        SELECT COUNT(*) INTO p_out_count        
        FROM employees;
       
        --Get data with pagination
        OPEN p_out_data FOR
        SELECT
            id
            ,name
            ,username
            ,email
            ,website
        FROM
            employees
        WHERE 1=1
        ORDER BY id
        OFFSET p_in_offset ROWS
        FETCH NEXT p_in_limit ROWS ONLY
        ;
       
        IF (p_in_offset + p_in_limit)>= p_out_count
        THEN
            p_out_has_more :=0;
            p_out_status    :='Success';
            p_out_message   :='Data fetched successfully';
        ELSE
            p_out_has_more :=1;
            p_out_status    :='Warning';
            p_out_message   :='No data found';
        END IF;
               
    EXCEPTION
        WHEN OTHERS THEN
            p_out_status    :='Error';
            p_out_message   :='Exception: '||SQLERRM;
    END get_data;
   
END EMP_DATA_PKG;
/
 
 
 
So, by calling this procedure in OIC you will be able to get the paginated data.
 
Below is the mapper file for mapping DB Adapter reponse to the REST response. Here we have used XSLT to get the field hasMore of response payload:
 
<xsl:template match="/" xml:id="id_11">
              <nstrgmpr:executeResponse xml:id="id_12">
                    <nstrgdfl:response-wrapper>

                          <xsl:choose>
                                <xsl:when test="$GetEmpDataFromDB/nsmpr0:OutputParameters/nsmpr0:P_OUT_HAS_MORE = 1">
                                      <nstrgdfl:hasMore>
                                            <xsl:value-of select="true()"/>
                                      </nstrgdfl:hasMore>
                                </xsl:when>
                                <xsl:otherwise>
                                      <nstrgdfl:hasMore>
                                            <xsl:value-of select="false()"/>
                                      </nstrgdfl:hasMore>
                                </xsl:otherwise>
                          </xsl:choose>

                          <nstrgdfl:totalCount>
                                <xsl:value-of select="$GetEmpDataFromDB/nsmpr0:OutputParameters/nsmpr0:P_OUT_COUNT"/>
                          </nstrgdfl:totalCount>

                          <xsl:for-each select="$GetEmpDataFromDB/nsmpr0:OutputParameters/nsmpr0:P_OUT_DATA/nsmpr0:Row">
                                <nstrgdfl:items>
                                      <nstrgdfl:id>
                                            <xsl:value-of select="nsmpr0:Column[@name='ID']"/>
                                      </nstrgdfl:id>
                                      <nstrgdfl:name>
                                            <xsl:value-of select="nsmpr0:Column[@name='NAME']"/>
                                      </nstrgdfl:name>
                                      <nstrgdfl:username>
                                            <xsl:value-of select="nsmpr0:Column[@name='USERNAME']"/>
                                      </nstrgdfl:username>
                                      <nstrgdfl:email>
                                            <xsl:value-of select="nsmpr0:Column[@name='EMAIL']"/>
                                      </nstrgdfl:email>
                                      <nstrgdfl:website>
                                            <xsl:value-of select="nsmpr0:Column[@name='WEBSITE']"/>
                                      </nstrgdfl:website>
                                </nstrgdfl:items>
                          </xsl:for-each>

                          <nstrgdfl:Status>
                                <xsl:value-of select="$GetEmpDataFromDB/nsmpr0:OutputParameters/nsmpr0:P_OUT_STATUS"/>
                          </nstrgdfl:Status>

                          <nstrgdfl:Message>
                                <xsl:value-of select="$GetEmpDataFromDB/nsmpr0:OutputParameters/nsmpr0:P_OUT_MESSAGE"/>
                          </nstrgdfl:Message>

                    </nstrgdfl:response-wrapper>
              </nstrgmpr:executeResponse>
        </xsl:template>


 

 



 

 

Comments

  1. Default values for offset and limit are wrong.

    ReplyDelete

Post a Comment

All Categories

Call Fusion BIP Report2 Change Password1 Code Combinations2 Compute Instance2 CTE1 Customer1 Data Aggregation2 Database5 Date Conversion1 DB Adapter2 Decryption1 Development1 EBS4 Encryption1 ESS Jobs3 Examine1 FBDI3 Fusion APIs1 Fusion BIP7 GIT2 GL3 GL Journals1 GL_DAILY_CONVERSION_TYPES1 GL_DAILY_RATES1 ICS1 Identity Domain1 Integrations1 Java1 Journal Import1 Keys1 Legal Entity1 LookupTypeLOV1 LOV1 LOVs1 MultiPartAPIs1 Networking1 NVL2 NVL in OIC2 OCI12 OCI Billing1 OCI Compute5 OCI Cost Management1 OCI Events Service1 OCI Free Tier3 oci networking1 OCI Notifification Service1 OCI Security3 OIC4 OIC Mapper2 Oracle26 Oracle ADF17 Oracle APEX1 Oracle Apps59 Oracle Apps R126 Oracle ATP1 Oracle BIP8 Oracle Cloud13 Oracle Cloud Free Tier1 Oracle cloud Infrastructure10 Oracle Cloud Security2 Oracle Cloud VM1 Oracle DB4 oracle ebs5 Oracle ERP4 Oracle ERP Adapter2 Oracle ERP Cloud7 Oracle financials2 Oracle Forms1 Oracle Fusion57 Oracle Fusion BIP4 Oracle Fusion ERP17 Oracle Fusion Financials18 Oracle Integration Cloud3 Oracle OAF17 Oracle OCI14 Oracle OIC22 Oracle SOA 12c10 Oracle SQL17 Oracle VBCS1 Oracle VBS2 Oracle Visual Builder Cloud Service1 Oracle Visual Builder Studio2 Oracle Workflow Notifications1 Others10 Payables2 Payables Import1 Properties1 R121 Register BIP as ESS Job1 Reset Password1 Responsibility1 REST4 Security List1 Site Map1 SOAP2 SOAP API2 SOAP UI3 SQL16 SQL Functions3 SQL Queries14 SQL Query8 SQL Tips3 SSH1 TCA1 Value Sets1 VBCS1 vcn1 Virtual Machine2 Virtual Machines1 XML1 XSLT1
Show more