4.6 Creating RESTful Web Services
Create RESTful web services using the Modules, Templates and Handlers pages.
To create a RESTful web service, you need to:
-
Define a resource module
-
Define a resource template
-
Define one or more resource handlers such as GET, PUT, POST or DELETE. Optionally, define parameters that you need to pass to the resource handler.
The following sections provide information on how to create resource modules, resource templates and resource handlers.
See Also:
-
Creating a RESTful Service in Oracle REST Data Services Quick Start Guide
4.6.1 Managing Resource Modules
You can define, edit and delete resource modules in the Modules page.
To navigate to the Modules page, in the REST Overview page, click Modules in Objects, or from the menu in the header, select Modules.
The module attributes displayed by default in card view are shown in the following figure.
The module status can be published or unpublished. If the status is unpublished, the icon is displayed in a red color.
Click the module name in card view to go to the Templates page for that module. You can also navigate to the Templates page through the context menu.
The actions available in the context menu are:
-
Navigating to the Templates page for a module
See Also:
About the REST Search Toolbar4.6.1.2 Importing a Resource Module
Note:
You can import an OpenAPI version 2.0 or 3.0 document in JSON format only.4.6.1.3 Editing a Resource Module
This section describes how to edit a resource module.
- In the Modules page, for the specific module, click
and select Edit.
- Edit the required fields and click Save. For a description of the fields, see Creating a Resource Module.
4.6.1.5 Publishing/Unpublishing a Resource Module
This section describes how to make a resource module available or not.
4.6.2 Managing Resource Templates
You can define, edit and delete resource templates for a module in the Templates page.
To navigate to this page, in the Modules page, click for a module and select Templates, or click the name
of the module in card view.
At the top of the page, the module card is available with context menu options such as Edit, Delete, Publish and Export.
The templates attributes displayed by default in card view are shown in the following figure.
Click the template name in card view to go to the Handlers page. You can also navigate to the Handlers page through the context menu.
The actions available in the context menu are:
-
Navigating to the Handlers page for the template
4.6.3 Managing Resource Handlers
You can create, edit and delete resource handlers for a template in the Handlers page.
To navigate to this page, in the Templates page, click for a template and select Handlers,
or click the name of the template in card view.
At the top of the page, the template card is available with context menu options such as Edit and Delete.
Tthe handler attributes displayed by default in card view are shown in the following figure.
The HTTP Method can be one of the following: GET, PUT, POST and DELETE.
You can navigate to the HTTP method page using the context menu. There are three tabs displayed in the HTTP method page: Source, Parameters and Pre-Authenticated Requests.
Note:
This option is not available if the template has all four handlers created (GET, POST, PUT, DELETE).The actions available in the context menu are:
-
Edit: See Editing a Resource Handler
-
Delete: See Deleting a Resource Handler
-
Details: See Viewing Resource Handler Details and Managing Parameters
-
Pre-Authenticated Requests: See Pre-authenticated Requests
4.6.3.4 Viewing Resource Handler Details and Managing Parameters
You can view resource handler details and manage parameters in the HTTP method page.
To navigate to this page, for a specific handler, click and then select Details or click the
name of the handler in card view.
At the top of the page, the handler card is available with context menu options such as Edit and Delete.
The Handler HTTP method page has two major sections:
-
A code editor for executing the SQL or PL/SQL source code that was defined in the resource handler. You can execute the code, save, undo, redo, download and clear output. For more information about the editor, see Executing SQL Statements in the Code Editor.
Implicit parameters used in REST service handlers are displayed in a scrolling list towards the right side of the editor. See Implicit Parameters
-
A section for managing parameters required for running the HTTP method.
By default, the parameters are displayed in grid view. The attributes displayed on a parameter in card view are shown in the following figure.
The actions available in the context menu are:
See Also:
About the REST Search Toolbar4.6.3.4.1 Creating a Parameter
This section describes how to create a parameter for a resource handler.
4.6.3.4.4 Implicit Parameters
This section describes the implicit parameters in the Resource Handler Details page. These parameters are automatically added to the resource handlers.
Table 4-1 Implicit Parameters
Name | Type | Access Mode | HTTP Header | Description |
---|---|---|---|---|
|
BLOB |
IN |
N/A |
Specifies the body of the request as a temporary BLOB. |
|
CLOB |
IN |
N/A |
Specifies the body of the request as a temporary CLOB. |
|
VARCHAR |
IN |
|
Specifies the MIME type of the request body, as indicated by the Content-Type request header. |
|
VARCHAR |
IN |
N/A |
Specifies the authenticated user for the request. If no user is authenticated, then the value is set to null. |
|
VARCHAR |
OUT |
|
Specifies the ___location where Oracle REST Data Services must forward a GET request to produce the response for this request. |
|
NUMBER |
IN |
N/A |
Specifies the zero-based offset of the first row to be displayed on a page. |
|
NUMBER |
IN |
N/A |
Specifies the maximum number of rows to be retrieved on a page. |
|
NUMBER |
IN |
N/A |
Specifies the zero based page offset in a paginated request. Note:
|
|
NUMBER |
IN |
N/A |
Specifies the maximum number of rows to be retrieved on a page. The |
|
NUMBER |
IN |
N/A |
Specifies the one-based index of the first row to be displayed in a paginated request. |
|
NUMBER |
IN |
N/A |
Specifies the one-based index of the last row to be displayed in a paginated request. |
|
NUMBER |
OUT |
|
Specifies the HTTP status code for the request. |
For more information about the implicit parameters, see Oracle REST Data Services Developer's Guide.
4.6.3.5 Using Pre-Authenticated Requests to Access ORDS RESTful Services
To access protected RESTful services, you can create and revoke pre-authenticated requests.
Pre-authenticated requests enable you to access protected ORDS RESTful services without user credentials. When you create pre-authenticated request, a unique URL is generated. You can provide this URL to an external user to interact with the particular RESTful entity using standard HTTP tools.
For more information about Pre-Authenticated Requests, see Oracle REST Data Services Pre-Authenticated Requests in the Oracle REST Data Services Developer's Guide.
To navigate to the Pre-Authenticated Requests page, you can do either of the following:
-
From the Overview page, click the Pre-Authenticated Requests tile.
-
From the menu bar, expand Security and select Pre-Authenticated Requests.
Topics:
4.6.3.5.1 Creating a Pre-Authenticated Request
To create a pre-authenticated request for an existing handler:
-
From the context menu for an existing handler, select Create New Pre-authenticated Request.
The Create Pre-authenticated Request panel appears.
-
In the Token Expiration field, enter the token expiry duration in seconds.
Select Show Code to view the underlying source code for creating the pre-authenticated request.
Click Create.
The token, alias, and relative link to access the resource are displayed. You must keep track of the token and alias as you cannot obtain their values later. If you forget the values, you can revoke the token and create a new one again.
4.6.3.5.2 Viewing a Pre-Authenticated Request
From the context menu for an existing handler, select Pre-Authenticated Requests and then select Details.
The pre-authenicated requests for the specific handler appears.
4.6.3.5.3 Revoking a Pre-Authenticated Request
To revoke the pre-authenticated request for a handler:
-
From the context menu for an existing handler, select Pre-Authenticated Requests and then select Details.
The pre-authenticated requests for the specific handler appears.
-
From the context menu for the pre-authenticated request, select Revoke.
You are prompted to confirm.
- Click Confirm to revoke the request.
4.6.4 Example: Inserting a Record using a POST Handler
The following example illustrates how to insert a record in the DEPT table.
Prerequisites
-
Using the worksheet in the SQL page, create a DEPT table.
CREATE TABLE DEPT( DEPTNO number(2,0), DNAME varchar2(14), LOC varchar2(13), CONSTRAINT PK_DEPT PRIMARY KEY (DEPTNO) )
-
Create a module named example. See Creating a Resource Module
-
Create a template named emp/ for the module. See Creating a Resource Template