This tutorial covers creating a RESTful Web Service and accessing the Web Service through an application in Application Express 5.1. It also covers consuming the Web Service using a REST client.
Time to Complete
Approximately 40 minutes.
Overview
Web Services enable applications to interact with one another over the web in a platform-neutral,language independent environment. In a typical Web Services scenario,a business application sends a request to a service at a given URL by using the protocol over HTTP. The service receives the request,processes it,and returns a response. Web Services are typically based on Simple Object Access Protocol (SOAP) or Representational State Transfer (REST) architectures. RESTful Web Services are result oriented. The scope of the Web Service is found in the URI and the method of the service is described by the HTTP method that is used such as GET,POST,PUT,and DELETE.The RESTful Web Service Wizard is a set of pages in the sql Workshop area of Oracle Application Express that help you to create a RESTful Web Service declaratively. Once you have defined a RESTful Web Service,you can call it with a unique Uniform Resource Identifier (URI). RESTful Web Services are organized within Oracle APEX through a hierarchy of a module,a resource template and handlers within a template. The resource template includes a prefix for the URI,which is completed with a final portion of the URI defined by the handler.
This tutorial covers creating a RESTful Web Service declaratively using Oracle Application Express's sql Workshop tool,and then consuming the same service by creating an application and adding a Web Service Reference to the RESTful Web Service. The RESTful Web Service is also consumed using a REST client.
Please keep in mind the following while running this tutorial:
- Logging into your Oracle Application Express workspace:Your Oracle Application Express workspace may reside in an on-premises Oracle Database or in Oracle Database Cloud Services. The login credentials differ depending on where your workspace is located:
- Logging into Oracle Application Express in a Oracle Database Cloud Service: Go to the Oracle Help Center for Cloud,and select Platform and Infrastructure. From here,select your Database Cloud Service and the Get Started page will appear.
- Logging in to Oracle Application Express on-premises: From your browser,go to the location of your on-premises installation of your Oracle Application Express workspace provided by your Workspace Administrator.
- Application ID:Screenshots in this tutorial show a blurred Application ID. Your Application ID can be any value assigned automatically while creating the application.
- Schema:If you are accessing an Oracle Application Express workspace in Database Schema Service,you have one schema assigned to you with a schema name that you cannot change. If you are accessing the workspace in an on-premises Oracle database,you may have more than one schema assigned to your workspace by the Oracle Application Express Instance Administrator.
What Do You Need?
Before starting this tutorial,you should:
- Have access to an Oracle Database 11.2.x.x or later release,including Enterprise Edition and Express Edition (Oracle Database XE),either on-premises or in a Database Cloud Service.
- Install Oracle Application Express Release 5.1 into your Oracle Database with RESTful Services configured in Oracle Application Express (for on-premises only).
- Download and unzip thefiles.zipinto your working directory.
- Execute
Create_Employees.sql
from the extracted files,to create required database objects.
In this topic,you create a RESTful Web Service using RESTful Services tool in sql Workshop. The RESTful Web Service Wizard is a set of pages in sql Workshop that help you to create a new RESTful Web Service declaratively. The RESTful Web Service calls a specific sql statement in your database.
Creating a RESTful Web Service with GET and PUT Resource Handlers
To create a RESTful Web Service on the Employees table with sample GET and PUT service handlers,perform the below steps:
From the Oracle Application Express Home page,select thesql Workshoptab and selectRESTful Services.
From the RESTful Services page,select theCreate a New RESTful Serviceoption.
A page loads with entries grouped under three different categories named RESTful Services Module,Resource Template,and Resource Handler. Under RESTful Services Module,enteremployeesfor Name,and scroll down further.
Under Resource Template,enteremployees/for URI Template to identify your Uniform Resource Identifier (URI),and scroll down further.
Under Resource Handler,selectGETfor Method,Queryfor Source Type,CSVfor Format. This identifies the HTTP method to be used for the Resource Handler.
Enter the following sql query for Source,and clickCreate Module.select * from employees
The GET Handler is created under employees/. To edit its properties,clickGETunder employees/.
SelectNofor Requires Secure Access,and clickApply Changes.
To test the behavior of the RESTful Service Handler,clickTest.
Note:If your screen does not show a Test button,please ensure that RESTful Services are configured in your Oracle Application Express installation properly.You are prompted to save the file which you can then view using a CSV editor.
The CSV format result set is displayed.
Let us now create a Handler for the POST method in the same Web Service. ClickCreate Handlerunder employees/.
SelectPOSTfor Method andPL/sqlfor Source Type. Enterapplication/jsonfor MIME Types Allowed. SelectNofor Requires Secure Access. Enter the following PL/sql code for Source,and clickCreate.
declare
id employees.employee_id%TYPE;
begin
id := employees_seq.nextval;
insert into employees
(employee_id,first_name,last_name,email,hire_date,job_id)
values
(id,:first_name,:last_name,:email,to_date(:hire_date,'DD-MM-YYYY'),
:job_id);
:employee_id := id;
end;Scroll down the page,and clickCreate Parameterto add an OUT parameter to the handler that will return the newly created employee’s ID.
Enteremployee_idfor Name and Bind Variable Name. SelectOUTfor Access Method,HTTP Headerfor Source Type,Stringfor Parameter Type,and clickCreate.
The OUT parameter is created.
ClickCreate Parameteragain to add the following IN parameters to the handler.
Name Bind Variable Name Access Method Parameter Type first_name first_name IN String email email IN String last_name last_name IN String hire_date hire_date IN String job_id job_id IN String In the next section,you create a new template to retrieve JSON result set based on Query One Row with a bind variable.
In this section,you will create a RESTful Service that provides detailed information of an employee,given the employee id. The result is returned in JSON format. Perform the following steps:
ClickCreate Template.
Enteremployees/{id}for URI Template,and clickCreate.
ClickCreate Handlerunder employees/{id}.
SelectGETfor Method,Query One Rowfor Source Type,andNofor Requires Secure Access.
Enter the following sql Query for Source,and clickCreate.select * from employees where employee_id = :id
Scroll down and clickCreate Parameter.
Enteridfor Name and Bind Variable Name. SelectINfor Access Method,and clickCreate.
You want to change the Source Type. Under Parameters,click theidlink under Name.
SelectURIfor Source Type,and clickApply Changes.
Before testing this handler,you have to set a bind variable to pass a value for the input parameter(id). ClickSet Bind Variables >.
Enter103for :ID,and clickTest.
Complete details of the employee with employee_id = 103 is displayed.
In this section,you will be creating a RESTful service of a feed source type. The feed results are rendered in JSON format. Each item in the feed contains a summary of a resource and a hyperlink to a full representation of the resource. Perform the below steps:
ClickCreate Template.
EnteremployeesFeed/for URI Template,and clickCreate.
Under employeesFeed/,clickCreate Handler.
SelectGETfor Method,Feedfor Source Type,andNofor Requires Secure Access. Under Source,enter the following sql query,and clickCreate.
select employee_id,first_name
from employees
order by employee_id,first_nameUnder
employeesFeed/
,clickGETto open the Resource Handler Editor.The results are rendered in JSON format. Each item consists of a URI which contains the base URI from this RESTful Service,and the value of employee_id used as the parameter. For the Feed source type,the first column must be a unique identifier. It will be transformed into a hyperlink when this RESTful Service is called.
In this example,employee_id is the first column and will turn into a hyperlink.
For example,in the screenshot shown below,the URI for an employee withemployee_id = 100
ishttps://:
Note:The URI shown in this example is specific to the database On-Premise subscription used for executing this tutorial,and it might be different for you. The value of the URI also depends on whether you are performing this tutorial On-Premises or on a Cloud Service. In general,the URI formats are as follows:<hostname>
:<port>/ords/hr/employeesFeed/100On-Premises http://localhost:<Port where ords is set up>/ords/<schema name>/<Resource Template Name>/<employee_id>
For example:http://localhost:9090/ords/hr/employeesFeed/100
where ords is set up on port9090during Oracle APEX installation,hris the schema name,employeesFeedis the Resource Template name,and100is the employee_id.On a Cloud Service <Service URL as received in the Welcome email from Oracle Cloud>/<Resource Template Name>/<employee_id>
For example:https://databasetrial:
where<user>
.db.us2.oraclecloudapps.com/hr/employeesFeed/100<user>
.db.us2.oraclecloudapps.com/hr/is the Service URL for the cloud service subscription,and100is the employee_id.Description of this image Select the URI for one of the employee_ids,and copy it to clipboard.
Description of this image Open a browser,paste the copied URI,and press Enter. Notice that the details of that particular employee are returned as a JSON result set.
Description of this image
In this section,you will be creating a RESTful service of a feed source type given the Department ID. The feed results are rendered as JSON. Perform the below steps:
ClickCreate Template.
Description of this image EnteremployeesFeed/{id},and clickCreate.
Description of this image Under employeesFeed/{id},clickCreate Handler.
Description of this image SelectGetfor Method,serif; padding: 3px; background-color: transparent; border-radius: 4px; line-height: 1.615; font-style: italic;">select employee_id,first_name
from employees
where department_id = :idDescription of this image Scroll down further,and clickCreate Parameter >to add an IN parameter to the handler that will receive the department_id.
Create. idlink under Name. Description of this image SelectURIfor Source Type,and clickApply Changes.
Description of this image Before testing this handler,you have to set bind variable to pass a value for the input parameter,id. ClickSet Bind Variables >.
Description of this image Enter60for :ID,and clickTest.
Description of this image The results are rendered in JSON format. Each item consists of a URI which contains the base URI from this RESTful Service,and the value of department_id used as the parameter. For the Feed source type,the first column must be unique identifier and will be transformed into a hyperlink when this RESTful Service is called.
In this example,department_id
is the first column and will turn into a hyperlink.
For example,the URI for an employee with department_id = 60 ishttp://
where page=1 indicates that these results are part of page 1. If there are many records in the result set,the results can span across page 2 and so on.<hostname>
:<port>/ords/hr/employeesFeed/60?page=1
Note:The URI shown in this example is specific to the database On-Premise service subscription used for executing this tutorial,the URI formats are as follows:On-Premises http://localhost:<Port where ords is set up>/ords/<schema name>/<Resource Template Name>/<department_id>?page=1
For example:http://localhost:9090/ords/hr/employeesFeed/60?page=1
where ords is set up on port9090
during Oracle APEX installation,serif; padding: 3px; background-color: transparent; border-radius: 4px; line-height: 1.615;">hris the schema name,serif; padding: 3px; background-color: transparent; border-radius: 4px; line-height: 1.615;">employeesFeedis the Resource Template name and60
is the department_id.On a Cloud Service <Service URL as received in the Welcome email from Oracle Cloud>/<Resource Template Name>/<department_id>?page=1
For example:https://databasetrial:<user>.db.us2.oraclecloudapps.com/hr/employeesFeed/60?page=1
/is the Service URL for the cloud service subscription,serif; padding: 3px; background-color: transparent; border-radius: 4px; line-height: 1.615;">
where<user>
.db.us2.oraclecloudapps.com/hremployeesFeed
is the Resource Template name,and60
is the department_id.Description of this image
In this topic,you consume the RESTful Web Service in Oracle Application Express by creating a database application and by creating a Web Service Reference in the application. You create a form and report page that uses the web service.
Note:If you are executing this tutorial On-Premises,make sure you have granted the connect privileges by executing theAPEX_ACL.sql
script from thefiles.zipfolder that you had downloaded and unzipped in the Prerequisites section of this tutorial.
From the Oracle Application Express home page,click the down arrow next to App Builder,and selectDatabase Applications.
Description of this image Click theCreate icon.
Description of this image Accept the default,and clickNext >.
Description of this image EnterRESTful Web Services Demofor Name,and clickNext >.
Description of this image ClickNext >.
Next >. Description of this image SelectApplication Express Accountsfor Authentication Scheme,and clickNext >.
Description of this image ClickCreate Application.
Description of this image The application is created. ClickShared Components.
Description of this image Under Data References,clickWeb Service References.
Description of this image ClickCreate >.
Box-sizing: border-Box; font-size: 14.0238px; border: 1px solid gray; vertical-align: middle; max-width: 100%; height: auto; padding: 4px; width: auto; display: block;" src="http://pic.sunansheng.com/csdn/74025246/creating_REST_02_11.png">
Description of this image SelectRESTfor What type of Web reference would you like to create,and clickNext >.
Description of this image Enteremployeesfor Name. SelectGETfor HTTP Method andNofor Basic Authentication. For the URL,enter the Web Reference URI for the GET Service Handler which was created in the first section of this tutorial.
As explained in the below table,your URI depends on the location of your Oracle Application Express instance,whether On-Premises or on a Database Cloud Service.On-Premises http://localhost:<Port where ords is set up>/ords/<schema name>/<Resource Template Name>/
For example:http://localhost:9090/ords/hr/employees/
where ords is set up on port9090during Oracle APEX installation,hris the schema name,employeesis the Resource Template name.On a Cloud Service <Service URL as received in the Welcome email from Oracle Cloud>/<Resource Template Name>/
For example:<user>
.db.us2.oraclecloudapps.com/hr/employees/
wherehttps: databasetrial:
<user>.db.us2.oraclecloudapps.com/hr/
is the Service URL for the cloud service subscription andemployeesis the Resource Template name.
Description of this image ClickNext >.
Description of this image There are no parameters defined for the GET Service Handier. So,click theDelete Parametericon for Input Parameters.
Description of this image ClickNext >.
Description of this image Now,you have to define the REST Outputs. SelectTextfor Output Format.Entercommafor Parameter Delimiter,and\nfor New Record Delimiter.
Under Output Parameters,enterEmployee IDfor Nameand1for Path. SelectStringfor Type,and clickAdd Parameter.Description of this image Similarly,add the following Output Parameters,and clickCreate.
Name Path Type Name 2 String Hire Date 6 String Job Id 7 String Description of this image Click theView Reporticon.
Description of this image Click theTesticon for employees.
Description of this image Employees' details is displayed in the Response section. ClickCancel.
Description of this image ClickApplication<n>in the breadcrumb.
Box-sizing: border-Box; font-size: 14.0238px; border: 1px solid gray; vertical-align: middle; max-width: 100%; height: auto; padding: 4px; width: auto; display: block;" src="http://pic.sunansheng.com/csdn/74025246/creating_REST_02_23.png">
Description of this image ClickCreate Page >.
Box-sizing: border-Box; font-size: 14.0238px; border: 1px solid gray; vertical-align: middle; max-width: 100%; height: auto; padding: 4px; width: auto; display: block;" src="http://pic.sunansheng.com/csdn/74025246/creating_REST_02_24.png">
Description of this image Click theFormicon.
Description of this image Click theReport and Formon Web Service icon.
Description of this image Selectemployeesfor Web Service Reference,doRESTfor Operation,and clickNext >.
Note:Employees appears in the select list for Web Service Reference because you added it under Web Service References in Shared Components.Description of this image ClickNext >.
Description of this image ClickNext >.
Description of this image Select all four parameters,that is,employee Id,Name,Hire Date,andJob Id. ClickNext >.
Description of this image Accept the default an clickNext >.
Description of this image ClickCreate.
Description of this image The new page is created. ClickSave and Run Page.
Description of this image Enter your Oracle Application Express credentials,and clickLog In.
Description of this image ClickSubmit.
Description of this image The Web Service is executed,and the results displayed.
Description of this image
In this section,you consume the Web Service that you have created in Oracle Application Express,using a REST Client.
Note:For the purpose of this tutorial,we will be using the RESTClient add-on in Firefox to demonstrate how to consume the RESTful Web Service created in APEX. You can also use other REST Clients such as,REST Easy and RESTer to perform these steps in Firefox. If you are using Google Chrome,you can install add-ons such as Postman to perform the steps.
Open Firefox and install theRESTClient,a debugger for RESTful web servicesadd-on to your browser.
Description of this image Open the installed add-on in your browser.
Description of this image To fetch the details of an employee,selectGETas the Request Method. For the URL,whether On-Premises or on a Database Cloud Service. In this example,
<hostname>
:<port>/ords/hr/employees/employeesis the URL used for theOn-Premise machine.On-Premises http://localhost:<Port where ords is set up>/ords/<schema name>/<Resource Template Name>/<Resource Handler>
For example:http://localhost:9090/ords/hr/employees/employees
where ords is set up on port9090during Oracle APEX installation,employeesis the Resource Template name andemployeesis the Resource Handler.On a Cloud Service <Service URL as received in the Welcome email from Oracle Cloud>/<Resource Template Name>/<Resource Handler>
For example:<user>
.db.us2.oraclecloudapps.com/hr/employees/employees
wherehttps: databasetrial:
<user>.db.us2.oraclecloudapps.com/hr/
is the Service URL for the cloud service subscription andemployeesis the Resource Template name andemployeesis the Resource Handler.ClickSEND.
Description of this image Select theResponse Body (Preview)tab to view all the employee records.
Description of this image To insert new values into the employees table,under Headers,selectCustom Header.
Description of this image EnterContent-Typeas Name,application/jsonas Value,and clickOK.
Description of this image In the RESTClient page,enterPOSTas the request method,enter the same URL as that of the GET method,enter the following code in the Request Body,and clickSEND.
{
"first_name":"Supriya",
"last_name":"Ananth",
"email":"SUPANANT",
"hire_date":"13-05-2001",
"job_id":"AD_PRES"
}Description of this image Under Response,selectResponses Header. You see that the new employee's information is added into the Employees table. The newly created employee’s ID is returned back to the application.
In this tutorial,you have learned how to:
- Create a RESTful Web Service with various Resource Handlers using Oracle Application Express.
- Create a RESTful Web Service Reference in Application Express.
- Consume the Web Service created in Application Express using a REST client.
Purpose
This tutorial covers creating a RESTful Web Service and accessing the Web Service through an application in Application Express 5.1. It also covers consuming the Web Service using a REST client.
Time to Complete
Approximately 40 minutes.
The RESTful Web Service Wizard is a set of pages in the SQL Workshop area of Oracle Application Express that help you to create a RESTful Web Service declaratively. Once you have defined a RESTful Web Service,and then consuming the same service by creating an application and adding a Web Service Reference to the RESTful Web Service. The RESTful Web Service is also consumed using a REST client.
Please keep in mind the following while running this tutorial:
- Logging into your Oracle Application Express workspace:Your Oracle Application Express workspace may reside in an on-premises Oracle Database or in Oracle Database Cloud Services. The login credentials differ depending on where your workspace is located:
- Logging into Oracle Application Express in a Oracle Database Cloud Service: Go to the Oracle Help Center for Cloud,select your Database Cloud Service and the Get Started page will appear.
- Logging in to Oracle Application Express on-premises: From your browser,go to the location of your on-premises installation of your Oracle Application Express workspace provided by your Workspace Administrator.
- Application ID:Screenshots in this tutorial show a blurred Application ID. Your Application ID can be any value assigned automatically while creating the application.
- Schema:If you are accessing an Oracle Application Express workspace in Database Schema Service,you may have more than one schema assigned to your workspace by the Oracle Application Express Instance Administrator.
What Do You Need?
Before starting this tutorial,you should:
- Have access to an Oracle Database 11.2.x.x or later release,either on-premises or in a Database Cloud Service.
- Install Oracle Application Express Release 5.1 into your Oracle Database with RESTful Services configured in Oracle Application Express (for on-premises only).
- Download and unzip thefiles.zipinto your working directory.
- Execute
Box-sizing: border-Box; font-size: 13px; font-family: menlo,to create required database objects.
In this topic,you create a RESTful Web Service using RESTful Services tool in sql Workshop. The RESTful Web Service Wizard is a set of pages in sql Workshop that help you to create a new RESTful Web Service declaratively. The RESTful Web Service calls a specific sql statement in your database.
Creating a RESTful Web Service with GET and PUT Resource Handlers
To create a RESTful Web Service on the Employees table with sample GET and PUT service handlers,perform the below steps:
From the Oracle Application Express Home page,select thesql Workshoptab and selectRESTful Services.
Description of this image From the RESTful Services page,select theCreate a New RESTful Serviceoption.
Description of this image A page loads with entries grouped under three different categories named RESTful Services Module,and scroll down further.
Description of this image Under Resource Template,and scroll down further.
Description of this image Under Resource Handler,serif; padding: 3px; background-color: transparent; border-radius: 4px; line-height: 1.615; font-style: italic;">select * from employees
Description of this image The GET Handler is created under employees/. To edit its properties,clickGETunder employees/.
Description of this image SelectNofor Requires Secure Access,and clickApply Changes.
Description of this image To test the behavior of the RESTful Service Handler,please ensure that RESTful Services are configured in your Oracle Application Express installation properly.
Description of this image You are prompted to save the file which you can then view using a CSV editor.
Description of this image The CSV format result set is displayed.
Description of this image Let us now create a Handler for the POST method in the same Web Service. ClickCreate Handlerunder employees/.
Description of this image SelectPOSTfor Method andPL/sqlfor Source Type. Enterapplication/jsonfor MIME Types Allowed. SelectNofor Requires Secure Access. Enter the following PL/sql code for Source,
:job_id);
:employee_id := id;
end;Description of this image Scroll down the page,and clickCreate Parameterto add an OUT parameter to the handler that will return the newly created employee’s ID.
Description of this image Enteremployee_idfor Name and Bind Variable Name. SelectOUTfor Access Method,and clickCreate.
Description of this image The OUT parameter is created.
Description of this image ClickCreate Parameteragain to add the following IN parameters to the handler.
Name Bind Variable Name Access Method Parameter Type first_name first_name IN String email email IN String last_name last_name IN String hire_date hire_date IN String job_id job_id IN String Description of this image In the next section,you create a new template to retrieve JSON result set based on Query One Row with a bind variable.
Creating a Resource Handler with Query One Row In this section,given the employee id. The result is returned in JSON format. Perform the following steps:
ClickCreate Template.
Description of this image Enteremployees/{id}for URI Template,and clickCreate.
Description of this image ClickCreate Handlerunder employees/{id}.
Description of this image SelectGETfor Method,serif; padding: 3px; background-color: transparent; border-radius: 4px; line-height: 1.615; font-style: italic;">select * from employees where employee_id = :id
Description of this image Scroll down and clickCreate Parameter.
Description of this image Enteridfor Name and Bind Variable Name. SelectINfor Access Method,and clickCreate.
Description of this image You want to change the Source Type. Under Parameters,click theidlink under Name.
Description of this image SelectURIfor Source Type,and clickApply Changes.
Description of this image Before testing this handler,you have to set a bind variable to pass a value for the input parameter(id). ClickSet Bind Variables >.
Description of this image Enter103for :ID,and clickTest.
Description of this image Complete details of the employee with employee_id = 103 is displayed.
Description of this image
Creating a Resource Handler with Employees Feed In this section,you will be creating a RESTful service of a feed source type. The feed results are rendered in JSON format. Each item in the feed contains a summary of a resource and a hyperlink to a full representation of the resource. Perform the below steps:
ClickCreate Template.
Description of this image EnteremployeesFeed/for URI Template,and clickCreate.
Description of this image Under employeesFeed/,clickCreate Handler.
Description of this image
SelectGETfor Method,first_name
Description of this image Under
Box-sizing: border-Box; font-size: 13px; font-family: menlo,clickGETto open the Resource Handler Editor.
Test. Description of this image The results are rendered in JSON format. Each item consists of a URI which contains the base URI from this RESTful Service,the URI formats are as follows:
On-Premises http://localhost:<Port where ords is set up>/ords/<schema name>/<Resource Template Name>/<employee_id>
For example:Box-sizing: border-Box; font-size: 13px; font-family: menlo,and100is the employee_id.
On a Cloud Service <Service URL as received in the Welcome email from Oracle Cloud>/<Resource Template Name>/<employee_id>
For example:Box-sizing: border-Box; font-size: 13px; font-family: menlo,and100is the employee_id.
Description of this image Select the URI for one of the employee_ids,and copy it to clipboard.
Description of this image Open a browser,and press Enter. Notice that the details of that particular employee are returned as a JSON result set.
Description of this image
Creating a Resource Handler with Employees Feed for a Given Department In this section,you will be creating a RESTful service of a feed source type given the Department ID. The feed results are rendered as JSON. Perform the below steps:
ClickCreate Template.
Description of this image EnteremployeesFeed/{id},and clickCreate.
Description of this image Under employeesFeed/{id},clickCreate Handler.
Description of this image SelectGetfor Method,first_name
from employees
where department_id = :idDescription of this image Scroll down further,and clickCreate Parameter >to add an IN parameter to the handler that will receive the department_id.
Create. idlink under Name. Description of this image SelectURIfor Source Type,and clickApply Changes.
Description of this image Before testing this handler,id. ClickSet Bind Variables >.
Description of this image Enter60for :ID,and clickTest.
Description of this image The results are rendered in JSON format. Each item consists of a URI which contains the base URI from this RESTful Service,the URI formats are as follows:
On-Premises http://localhost:<Port where ords is set up>/ords/<schema name>/<Resource Template Name>/<department_id>?page=1
For example:60
is the department_id.On a Cloud Service <Service URL as received in the Welcome email from Oracle Cloud>/<Resource Template Name>/<department_id>?page=1
For example:60
is the department_id.Description of this image
In this topic,you consume the RESTful Web Service in Oracle Application Express by creating a database application and by creating a Web Service Reference in the application. You create a form and report page that uses the web service.
Note:If you are executing this tutorial On-Premises,147); text-decoration-line: none;" rel="nofollow">files.zipfolder that you had downloaded and unzipped in the Prerequisites section of this tutorial.
From the Oracle Application Express home page,and selectDatabase Applications.
Description of this image Click theCreate icon.
Description of this image Accept the default,and clickNext >.
Description of this image EnterRESTful Web Services Demofor Name,and clickNext >.
Description of this image ClickNext >.
Next >. Description of this image SelectApplication Express Accountsfor Authentication Scheme,and clickNext >.
Description of this image ClickCreate Application.
Description of this image The application is created. ClickShared Components.
Description of this image Under Data References,clickWeb Service References.
Description of this image ClickCreate >.
Box-sizing: border-Box; font-size: 14.0238px; border: 1px solid gray; vertical-align: middle; max-width: 100%; height: auto; padding: 4px; width: auto; display: block;" src="http://pic.sunansheng.com/csdn/74025246/creating_REST_02_11.png">
Description of this image SelectRESTfor What type of Web reference would you like to create,and clickNext >.
Description of this image Enteremployeesfor Name. SelectGETfor HTTP Method andNofor Basic Authentication. For the URL,serif; padding: 3px; background-color: transparent; border-radius: 4px; line-height: 1.615;">
On-Premises http://localhost:<Port where ords is set up>/ords/<schema name>/<Resource Template Name>/
For example:Box-sizing: border-Box; font-size: 13px; font-family: menlo,employeesis the Resource Template name.
On a Cloud Service <Service URL as received in the Welcome email from Oracle Cloud>/<Resource Template Name>/
For example:https: databasetrial:
<user>.db.us2.oraclecloudapps.com/hr/
is the Service URL for the cloud service subscription andemployeesis the Resource Template name.
Description of this image ClickNext >.
Description of this image There are no parameters defined for the GET Service Handier. So,click theDelete Parametericon for Input Parameters.
Description of this image ClickNext >.
Description of this image Now,and clickAdd Parameter.
Description of this image Similarly,and clickCreate.
Name Path Type Name 2 String Hire Date 6 String Job Id 7 String Description of this image Click theView Reporticon.
Description of this image Click theTesticon for employees.
Description of this image Employees' details is displayed in the Response section. ClickCancel.
Description of this image ClickApplication<n>in the breadcrumb.
Box-sizing: border-Box; font-size: 14.0238px; border: 1px solid gray; vertical-align: middle; max-width: 100%; height: auto; padding: 4px; width: auto; display: block;" src="http://pic.sunansheng.com/csdn/74025246/creating_REST_02_23.png">
Description of this image ClickCreate Page >.
Box-sizing: border-Box; font-size: 14.0238px; border: 1px solid gray; vertical-align: middle; max-width: 100%; height: auto; padding: 4px; width: auto; display: block;" src="http://pic.sunansheng.com/csdn/74025246/creating_REST_02_24.png">
Description of this image Click theFormicon.
Description of this image Click theReport and Formon Web Service icon.
Description of this image Selectemployeesfor Web Service Reference,and clickNext >.
Note:Employees appears in the select list for Web Service Reference because you added it under Web Service References in Shared Components.Description of this image ClickNext >.
Description of this image ClickNext >.
Description of this image Select all four parameters,andJob Id. ClickNext >.
Description of this image Accept the default an clickNext >.
Description of this image ClickCreate.
Description of this image The new page is created. ClickSave and Run Page.
Description of this image Enter your Oracle Application Express credentials,and clickLog In.
Description of this image ClickSubmit.
Description of this image The Web Service is executed,and the results displayed.
Description of this image
In this section,using a REST Client.
Note:For the purpose of this tutorial,you can install add-ons such as Postman to perform the steps.
Open Firefox and install theRESTClient,a debugger for RESTful web servicesadd-on to your browser.
Description of this image Open the installed add-on in your browser.
Description of this image To fetch the details of an employee,serif; padding: 3px; background-color: transparent; border-radius: 4px; line-height: 1.615;"><hostname>:<port>/ords/hr/employees/employeesis the URL used for theOn-Premise machine.
On-Premises http://localhost:<Port where ords is set up>/ords/<schema name>/<Resource Template Name>/<Resource Handler>
For example:Box-sizing: border-Box; font-size: 13px; font-family: menlo,employeesis the Resource Template name andemployeesis the Resource Handler.
On a Cloud Service <Service URL as received in the Welcome email from Oracle Cloud>/<Resource Template Name>/<Resource Handler>
For example:https: databasetrial:
<user>.db.us2.oraclecloudapps.com/hr/
is the Service URL for the cloud service subscription andemployeesis the Resource Template name andemployeesis the Resource Handler.ClickSEND.
Description of this image Select theResponse Body (Preview)tab to view all the employee records.
Description of this image To insert new values into the employees table,selectCustom Header.
Description of this image EnterContent-Typeas Name,and clickOK.
Description of this image In the RESTClient page,
"job_id":"AD_PRES"
}Description of this image Under Response,selectResponses Header. You see that the new employee's information is added into the Employees table. The newly created employee’s ID is returned back to the application.
In this tutorial,you have learned how to:
- Create a RESTful Web Service with varIoUs Resource Handlers using Oracle Application Express.
- Create a RESTful Web Service Reference in Application Express.
- Consume the Web Service created in Application Express using a REST client.