Sunday, July 26, 2020

Consuming RESTful services in Oracle APEX

Let's see how we can consume REST webservices in Oracle APEX. Before we proceed, the assumption is that you are aware of REST concepts or you can refer my blogpost that explains basics of REST architecture - Check it here


We are going to use an example of Bing maps REST API where we will pass various parameters such as from and to addresses and will try to derive and consume all possible mileage values returned by REST API.


First thing first. Let’s understand structure of Bing Maps REST services.

The base URL Structure is as follows –


https://dev.virtualearth.net/REST/version/restApi/resourcePath?queryParameters&key=BingMapsKey


Here's a sample REST call using this API –


https://dev.virtualearth.net/REST/V1/Routes/Driving?&waypoint.0=9410 Webb Chapel Rd, Dallas, TX 75220&waypoint.1=5959 Royal Ln, Dallas, TX 75230&maxSolutions=2&distanceUnit=mi&key=h2d5aewr6_i8768a-9ftw54js7-876asdfasf


Now let’s see how we can consume the REST webservice in Oracle APEX -


1. Make the webservice call using APEX_WEB_SERVICE.make_rest_request API


lc_clob := APEX_WEB_SERVICE.make_rest_request (
p_url => 'http://dev.virtualearth.net/REST/V1/Routes/Driving?o=xml'||'&'||'wp.0=4122%20Avondale%20Ave,%20Dallas,%20TX%2075219'||'&'||'wp.1=3837%20Caruth%20Blvd,%20Dallas,%20TX%2075225'||'&'||'maxSolns=3'||'&'||'du=mi'||'&'||'key= h2d5aewr6_i8768a-9ftw54js7-876asdfasf',p_http_method => 'GET'
);

2. Next, we'll use APEX_WEB_SERVICE.parse_xml API to extract a specific node of the XML document stored in the XMLTYPE, and we can store it in a locally declared VARCHAR2 variable.


But before that, let's check if Status Code returned by REST API was 200 (i.e. OK) by making the call below -


lv_rest_status :=
APEX_WEB_SERVICE.parse_xml (
p_xml => XMLTYPE(lc_clob),
p_xpath => '//Response/StatusCode'
);

3. Now let’s make the final API call to retrieve actual mileages returned by the REST webservice -


lv_mileages := 
APEX_WEB_SERVICE.parse_xml (
p_xml => XMLTYPE(lc_clob),
p_xpath => '//Response/ResourceSets/ResourceSet/Resources/Route/TravelDistance'
);

This will return all the requested mileage values indicated by TravelDistance nodes as shown below.


<TravelDistance>3.375288</TravelDistance><TravelDistance>5.857666</TravelDistance><TravelDistance>8.010096</TravelDistance>


This is a simple example of how we can consume simple REST webservices in Oracle APEX. The complication of this process depends on the type of REST webservice we are consuming and complexity of data set we are retrieving and parsing, but the basic process follows the aforementioned flow.

Share:

Sunday, June 14, 2020

What are RESTful Webservices

Information exchange among internal and/or external systems is an essential part of an organization’s IT division. To achieve these integrations, one can use Representational State Transfer (REST) APIs instead of using traditional file transfers.


So, what are REST APIs?

REST being an architectural style, takes a resource-based approach to web-based interactions. With REST, you locate a resource on the server, and you can either update that resource, delete it or get more information about it.


RESTful services are lightweight web services for the transfer of representation of resources through requests and responses.

RESTful services utilize the primary or most-commonly-used HTTP methods POST, GET, PUT and DELETE. These correspond to create, read, update, and delete (or CRUD) operations, respectively. (There are several other less frequently used verbs, too.)



REST APIs use the Status-Line part of the HTTP response message to notify a REST client of their request’s result. Each response to a request provides an HTTP status code. 2xx codes indicate success, while 4xx and 5xx codes denote client or server errors.



How does REST compare with SOAP


REST being an architectural style, takes a resource-based approach to web-based interactions. With REST, you locate a resource on the server, and you can either update that resource, delete it or get more information about it. REST is simple, scalable and optimized for web REST is data driven. REST allows many data formats such as XML, JSON, plain text, HTML


As SOAP is a protocol, the client doesn't choose to interact directly with a resource, but instead calls a service and that service moderates the access to the various objects and resources behind the scenes. SOAP is a much complex in structure than REST SOAP is function driven. SOAP only allows XML SOAP has tighter security as WS-Security is a built-in in addition to SSL support


Share:

Thursday, May 14, 2020

How to collapse Navigation Menu on page load in Oracle APEX

By default, an APEX application shows the navigation menu on the left hand side and it's expanded by default when the application or a page loads.


What if you want to display it in Collapsed state by default ? Is it possible ?


Yes, this can be done in two ways. Let's see how to achieve this.


Method 1 -


You can set this at design time so that the Navigation menu is displayed collapsed by default when the application loads.


To do this -

- Navigate to Shared Components

- User Interface Attributes -> Navigation Menu

- Under Template Options, uncheck 'Use Template Defaults' and check 'Collapsed by Default (Default)' option

- Apply Changes




Method 2 -


Above method will let you hide Navigation menu but it won't be conditional as it will take effect when the application loads.


What if you want to hide the Navigation menu when a particular page loads ?


Let's take an example of below page. By default it will look like this with expanded Navigation Menu -



Let's hide the Navigation menu conditionally.


To do this -

- Navigate to the desired page definition

- Go to Dynamic Actions section

- Create a new DA on Page Load

- In True section, set Action as Execute JavaScript Code

- Enter below code -

$('#t_Button_navControl').click();

- Save





Now when you run the application and navigate to this particular page, the page will open and the Navigation Menu will be collapsed giving the page more space on screen.



Share: