Learn how to create the RESTful service module example.
Oracle Application Express workspace by default has an example RESTful Service Module, oracle.example.hr
.
oracle.example.hr
.Every workspace includes the example RESTful Service Module, oracle.example.hr
.
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:
empinfo/
- Employee information from the employees emp
table is returned in CSV format.
employees/
- Employee information from the employees emp
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.
employees/{id}
- Employee information from the employees emp
table for a specified id
is returned. The curly bracket identifies the parameter sent as part of the URI.
employeesfeed
/ - Employee information from the employees emp
table is returned as a JSON Feed.
employeesfeed/{id}
- Employee information from the employees emp
table for a specified id
is displayed in JSON format. The curly bracket identifies the parameter sent as part of the URI.
empsec/{empname}
- Employee information for a specified employee name, empname
, is returned and displayed in JSON. The curly bracket identifies the parameter sent as part of the URI.
empsecformat/{empname}
- Employee information for a specified employee name, empname
, is returned and formatted based on the execution of a PL/SQL block. The curly bracket identifies the parameter sent as part of the URI.
The following result is expected for the employees/[id]
resource template when the PUT resource handler is invoked:
employees/{id}
- Employee information from the employees emp
table for a specified id is updated. The curly bracket identifies the parameter sent as part of the URI. A status code is returned, which can be use to verify the success of the request.
See Also:
Oracle Learning Library for additional RESTful Service examples. Go to: http://www.oracle.com/oll/apex
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:
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:
Note:
If your results are not correct, compare your employees/{id}
GET resource handler with the oracle.example.hr
employees/{id}
GET resource handler.
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:
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:
Note:
If your results are not correct, compare your employeesfeed/
GET resource handler with the oracle.example.hr
employeesfeed
GET resource handler.
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:
Note:
If your results are not correct, compare your empsecformat/{empname}
GET resource handler with the oracle.example.hr
empsecformat/{empname}
GET resource handler.
employees/{id}
)You can add and test your own resource template that updates employee data based on a parameter.
The oracle.example.hr
module includes the employees/{id}
resource template to demonstrate a RESTful Service that updates one row of data in JSON format based on the specified id, and returns a HTTP status code, to verify the success of the request.
To add and test your own resource template that updates employee data based on a parameter:
Note:
If your results are not correct, compare your employees/{id}
PUT resource handler with the oracle.example.hr
employees/{id}
PUT resource handler.