7.5 How to Create the ORDS Based RESTful Services Module Example
Learn how to create the ORDS Based RESTful Services module example.
Oracle Application Express workspace by default has an example RESTful Service Module, oracle.example.hr
. You can install the sample service while registering the schema with ORDS.
- About the Example RESTful Service Module (oracle.example.hr)
In ORDS Based RESTful Services, you can choose to install the sample serviceoracle.example.hr
, when registering schema with ORDS. - Returning the Result Set Based on a PL/SQL Block (empsecformat/:empname)
You can add and test your own resource template that uses a PL/SQL block to format results. - Returning the Result Set in JSON Format with Pagination Set (employees/)
You can add and test your own resource template that retrieves data in JSON format and demonstrates pagination. - Retrieving Data Based on a Parameter (employees/:id)
You can add and test your own resource template that retrieves employee data based on a parameter. - Returning the Result Set in CSV Format (empinfo/)
You can build and test your own example RESTful Service Module that retrieves data in CSV format. - Returning the Result Set as a Feed (employeesfeed/)
You can add and test your own resource template that displays return data as a feed.
Parent topic: Enabling Data Exchange with RESTful Services
7.5.1 About the Example RESTful Service Module (oracle.example.hr)
In ORDS Based RESTful Services, you can choose to install the sample service oracle.example.hr
, when registering schema with ORDS.
This module provides example resource templates and resource handlers that implement several different methods to retrieve and display employee information from the emp
table. To access the oracle.example.hr
module, see “ Accessing RESTful Services”.
The oracle.example.hr
module consists of several resource templates. Each resource template demonstrates a different way of retrieving information and formatting the returned results.
The following results are expected for each oracle.example.hr
resource template when the respective GET resource handler is invoked:
-
empsec/:empname
- Employee information for a specified employee name,empname
, is returned and displayed in JSON. -
empsecformat/:empname
- Employee information for a specified employee name,empname
, is returned and formatted based on the execution of a PL/SQL block. -
employees/
- Employee information from the employeesemp
table is displayed in JSON format with Pagination Size set to 7. A first, previous and next link is provided to page through the results. -
version/
- Returns the version of the RESTful service module. -
employees/:id
- Employee information from the employeesemp
table for a specifiedid
is returned. -
empinfo/
- Employee information from the employeesemp
table is returned in CSV format. -
employeesfeed
/ - Employee information from the employeesemp
table is returned as a JSON Feed. -
employeesfeed/:id
- Employee information from the employeesemp
table for a specifiedid
is displayed in JSON format.
The following result is expected for the employees/:id
resource template when the PUT resource handler is invoked:
-
employees/:id
- Employee information from the employeesemp
table for a specified id is updated.
See Also:
-
Oracle Learning Library for additional RESTful Service examples. Go to: http://www.oracle.com/oll/apex
7.5.2 Returning the Result Set Based on a PL/SQL Block (empsecformat/:empname
)
You can add and test your own resource template that uses a PL/SQL block to format results.
The oracle.example.hr
module includes the empsecformat/:empname
resource template to demonstrate a RESTful Service that returns the results of an SQL Query formatted by a PL/SQL block.
To add and test your own resource template that uses a PL/SQL block to format results:
7.5.3 Returning the Result Set in JSON Format with Pagination Set (employees/
)
You can add and test your own resource template that retrieves data in JSON format and demonstrates pagination.
The oracle.example.hr
module includes the employees/
resource template to demonstrate a RESTful Service that returns data in JSON format. This example is returning the Result Set in JSON Format with Pagination Set Using Pagination Bind Variables. The Pagination bind variables are :row_offset
and :row_count
.
For other example resource templates that return results in JSON format see the empsec/{empname}
resource template for the oracle.example.hr
Service Module.
To add and test your own resource template that retrieves data in JSON format and demonstrates pagination:
7.5.4 Retrieving Data Based on a Parameter (employees/:id
)
You can add and test your own resource template that retrieves employee data based on a parameter.
The oracle.example.hr
module includes the employees/:id
resource template to demonstrate a RESTful Service that returns one row of data in JSON format based on the specified id
.
For other example resource templates that return results based on a specified parameter see the employeesfeed/:id
, empsec/:empname
and empsecformat/:empname
resource templates for the oracle.example.hr
Service Module.
To add and test your own resource template that retrieves employee data based on a parameter:
7.5.5 Returning the Result Set in CSV Format (empinfo/
)
You can build and test your own example RESTful Service Module that retrieves data in CSV format.
The oracle.example.hr
module includes the empinfo/
resource template to demonstrate a RESTful Service that returns data in CSV format. In this example, all the employee data from the emp
table is returned by using a SQL Query.
To build and test your own example RESTful Service Module that retrieves data in CSV format:
7.5.6 Returning the Result Set as a Feed (employeesfeed
/)
You can add and test your own resource template that displays return data as a feed.
The oracle.example.hr
module includes the employeesfeed/
resource template to demonstrate a RESTful Service that returns empno
and ename
values from the emp
table and displays them as a feed.
A feed resource handler executes a SQL query and transforms the results into a JSON Feed representation. Each item in the feed contains a summary of a resource and a hyperlink to a full representation of the resource. The first column in each row in the result set must be a unique identifier for the row and is used to form a hyperlink of the form: path/to/feed/{id}, with the value of the first column being used as the value for {id}. The other columns in the row are assumed to summarize the resource and are included in the feed. A separate resource template for the full representation of the resource should also be defined.
To add and test your own resource template that displays return data as a feed: