Skip to content

How to do a GET request to a REST Endpoint

A GET request is send to a REST endpoint to recieve information about a resource. In this case the request body is empty. The following example highlights how a GET request is put to the Paypal Rest API to get Credic Card information.


CREATE OR REPLACE PACKAGE BODY Paypal_Rest AS  
PROCEDURE test_paypal_rest IS  
Query_params PLSQLAP_DOCUMENT_API.Document;  
Url_params PLSQLAP_DOCUMENT_API.Document;  
BEGIN  
Url_params := PLSQLAP_DOCUMENT_API.New_Document('URL_PARAMETERS');  
PLSQLAP_DOCUMENT_API.Add_Attribute(Url_params,'param1', 'v1/vault/credit-cards');  
Query_params := PLSQLAP_RECORD_API.New_Record('QUERY_PARAMETERS');  
PLSQLAP_DOCUMENT_API.Add_Attribute(Query_params,'page_size', '5');  
PLSQLAP_DOCUMENT_API.Add_Attribute(Query_params,'page', '3');  
PLSQLAP_DOCUMENT_API.Add_Attribute(Query_params,'start_time', '2018-05-03T02:51:40Z');  

plsql_rest_sender_API.Call_Rest_EndPoint_Empty_Body2(rest_service => 'PAYPAL_CC_INFO',  
                                          url_params => Url_params,  
                                                        callback_func => 'Rest_Test_API.REST_callback_Test',  
                                                        http_method => 'GET',  
                                                        http_req_headers => 'Content-Type:application/json',  
                                                        query_parameters => Query_params);  

END test_paypal_rest;  
END Paypal_Rest;  



Important points to consider:

  • When configuring the REST sender for the REST service as a routing address we only configure the root URL of the REST service. To construct the exact path of the resource that we wish to send the GET request to we have to create a record structure in the PL/SQL code. Then set the values for the place holders that is specified in the REST Routing address in that record structure. In the code sample above the variable Url_params is used for this purpose.
  • A call to a REST resoruce can contain URL query parameters. This is used in GET calls to limit the number is resources returned in the response. You can specify these using a record strucutre and set the parameters and the values associated with them. In the above example the variable Query_params is used for this purpose.
  • To send a GET request you have to call the PL/SQL method plsql_rest_sender_API.Call_Rest_EndPoint_Empty_Body(..). Note that we don't set any payload to a GET request.