6.8 Managing Resource Handlers

A resource handler is a query or an anonymous PL/SQL block responsible for handling a particular HTTP method.

Multiple resource handlers can be defined for a resource template, however only one resource handler can be defined for a HTTP method.

Parameters to a resource handler can be manually defined to bind HTTP headers to the resource handler, or to cast a URI template parameter to a specific data type. Parameters declared in the URI template are implicitly passed to the resource handler. For example, a resource handler might need to know the value of the HTTP Accept-Language header in order to localize the generated representation.

6.8.1 Adding a Resource Handler

Learn how to add a resource handler to a resource template.

To add a resource handler to a resource template:

  1. On the Workspace home page, click SQL Workshop and then RESTful Services.

    The RESTful Services home page appears.

  2. Click the RESTful Service you want to add a resource handler to.

    The RESTful Service Module page appears.

  3. On the left panel, under the associated resource template, click Create Handler.

    The resource handler settings appear on the right panel.

  4. Fill in the appropriate fields and select the appropriate options. Mandatory fields are marked with a red asterisk (*). To learn more about a specific option, see the field-level help.
  5. Under Resource Handler, specify the following:
    • Method - Specify the HTTP method to be used for the resource handler. See field-level help.

    • Source Type - Identify the strategy type used to generate the resource. See field-level help.

    • Requires Secure Access - Identify whether the resource should be accessed over a secure channel, for example, HTTPS. Set to Yes if secure access is required

    • Pagination Size - Identify the size of the pagination window. For database queries, this is the number of rows to return.

  6. Under Source, enter the SQL query or PL/SQL block responsible for handling the selected HTTP method. Click Example at the bottom of the page for further details.
  7. Click Create.

    The RESTful Services Module page appears.

  8. To add parameters to the resource handler:
    1. Click Create Parameter.

      The parameter settings appear on the Resource Handler Parameter panel.

    2. For Name, enter the identifying parameter name.

    3. For Bind Variable Name, enter the parameter bind variable name used within the SQL query or PL/SQL block.

    4. For Access Method, select the HTTP method. Options include IN, IN/OUT, or OUT. URI Template parameters can only be IN. A value of IN for a header parameter implies the header will be present in the HTTP request. A value of IN/OUT indicates the value will be present in both the HTTP request and response. A value of OUT indicates the value will only be present in the HTTP response.

    5. For Source Type, select the parameter source type.

    6. For Parameter Type, select the data type of the parameter.

    7. Click Create.

      The resource handler page appears with the added parameter included under Parameters at the bottom of the right panel.

    8. For each parameter you want to add, repeat the above steps in this subsection.

  9. To test the behavior of the resource handler:
    1. Click Apply Changes.

    2. If you have bind variables in your SQL query or PL/SQL block, click Set Bind Variables and define the bind variables before testing.

    3. Click Test.

      A new window appears displaying the JSON result of executing the RESTful Service. The URL used in the test is composed of the value of the URI prefix and URI Template, along with any parameters.

    Note:

    The Test button and Set Bind Variables test options should only be used for the testing of GET methods, and not for the testing of the other three supported methods: PUT, POST, DELETE.

    Note:

    To make the test results easier to read, the installation of a JSON Viewer in your browser is recommended.

6.8.2 Editing a Resource Handler

Learn how to edit a resource handler.

To edit a resource handler:

  1. On the Workspace home page, click SQL Workshop and then RESTful Services.

    The RESTful Services home page appears.

  2. Click the name of the Resource Service Module the resource handler belongs to.

    The RESTful Service Module page appears.

  3. On the RESTful Service tree, click the resource handler you want to edit.

    The resource handler settings appears on the right panel.

  4. Make the changes you want.
  5. Click Apply Changes.

    The RESTful Service Module page appears.

6.8.3 Deleting a Resource Handler

Learn how to delete a resource handler.

To delete a resource handler:

  1. On the Workspace home page, click SQL Workshop and then RESTful Services.

    The RESTful Services home page appears.

  2. Click the name of the module the resource handler belongs to.

    The RESTful Service Module page appears.

  3. On the RESTful Service tree, click the resource handler you want to delete.

    The resource handler settings appear on the right panel.

  4. Click Delete.
  5. Click OK to confirm.

    The RESTful Service Module appears.