Test your API Using the REST Lab

You can test retrieval and update logic without writing programs, including provisions for REST parameters, using the REST Lab.
lac53
You can test retrieval and update logic without writing programs, including provisions for REST parameters, using the REST Lab. You can manage and test data using the REST Lab.
In this article:
3
Test Retrieval and Update Logic in the REST Lab
  1. With your API open, in the Tools section, click
    REST Lab
    .
    The
    Request
    tab opens by default. The following image shows this page:
    Screen Shot 2017-06-15 at 6.58.17 PM.png
  2. Complete the following, and then send your request by clicking
    GET
    ,
    POST
    ,
    PUT
    , or
    DELETE
    :
    1. Select the endpoint on which you want to operate.
      Options:
      The available endpoints are available.
    2. Select the named endpoint.
    You can specify the request content-type as application/json or application/xml.
    The JSON response appears in the
    Response
    pane. For POST
    or PUT requests, the updated row is displayed in the JSON response. The status code and Content-Type are displayed.
  3. Modify the response by selecting the
    Args
    checkbox.For more information about this checkbox, see Response Formats.
Include Rule Summary, Transaction Summary, and Exclude Metadata
By default, REST requests include the rule summary and the transaction summary and exclude the metadata. You can specify whether REST requests include or exclude this information. To include this information in REST requests, select the
Include Rule Summary
checkbox, the
Include Transaction Summary
checkbox, and the
Exclude Metadata
checkbox. These checkboxes display when you select the
Args
checkbox.
You can revert to the default settings by clearing the checkboxes.
Retrieve Data with Filters or Sorts using GET
You can retrieve data with filters or sorts using GET. REST retrieval requests commonly specify filtering and sorting for the top-most resource. Because filters and sorts are coded into the URL, employ proper escape sequences.
You can specify filtering and sorting using the URL Encode/Decode tool.
Specify System Sorts, System Filters, and User Sorts
You can allow different types of named filters and named sorts. Specify system sorts and filters or user sorts and filters to your GET query.
Follow these steps:
  1. In the REST Lab, on the Request page, select the
    Args
    checkbox.
    The following image shows this checkbox:
    Screen Shot 2017-06-15 at 7.09.56 PM.png
  2. Click
    Add Filter
    .
    The following image shows the options:
    Screen Shot 2017-06-15 at 7.13.21 PM.png
  3. Choose
    sysfilter
    (system filter) and
    sysorder
    (system sort) from the drop-down, and then enter your filter parameters. You can uppercase a specific system filter by adding the suffix
    _uc
    (for example,
    equals_uc
    ).
Examples
The following code snippet is a GET using a simple filter:
http://localhost:8080/rest/default/demo/v1/customer?filter=name%3D%27Alpha+and+Sons%27
To test using
filter
and
order
instead of named filters, turn on regular filters and sorts.
For more information:
The following code snippet is a GET request for customers with name < 'Shari', ordered by name (descending):
http://localhost:8080/rest/default/sample/v1/customers?filter=name%3C%27Shar%27&order=name%20desc,balance
Depending on your database and settings, you might require quoted identifiers, such as shown in the following code snippet (for the
Demo
API):
http://localhost:8080/rest/default/demo/v1/demo:customer?filter="name" like 'A%'
Filters are SQL WHERE clauses, so you can use familiar functions such as
like
:
http://localhost:8080/rest/default/demo/v1/customer?filter=name%20like%20%27Alpha%%27
Depending on the database type to which you are connected, there are other SQL syntax rules that can affect filter results. For example, you can interchange quotes for double-quotes, check for null (
filter=name+IS+NOT+NULL
), and put quotes around the column names. GET simplifies filter testing by providing automatic HTTP escapes.
Test Functions in the REST Lab
You can test your functions in the REST Lab. You can select top-level functions as endpoints from the list. For resource-oriented functions, you can enter the URL directly into the URL field.
You can get to the REST Lab from the function.
  1. On the
    By function
    tab, click the top-level function as an endpoint that you want to test from the list of functions. For resource-oriented functions, enter the URL directly in the REST Lab.
    The
    Definition
    tab appears.
  2. Click
    Test
    .
  3. To return to the
    Definition
    tab for the function, from the REST Lab, click
    Edit
    .
Follow these steps:
  1. In the REST Lab, select the
    Function
    endpoint.
  2. Do
    one
    of the following, and then click
    GET
    :
    • To select a top-level function as an endpoint
      , select the function from the list.
      The URL that displays in the URL field includes the parameters (string, number, boolean) for the function. Modify this URL with the parameter values that you want to pass into the function.
    • To select a resource-oriented function
      , enter the URL for the function in the URL field.
Test Metadata Endpoints in the REST Lab
  1. In the REST Lab, select the
    Metadata
    endpoint.
    The metadata endpoints display.
  2. Select the endpoint, and then click
    GET
    .
Investigate the Results of your Request's Logic
After updates, such as POST, PUT, DELETE requests, you can investigate the results of your request's logic by exploring the following summaries:
  • The transaction summary
  • The rule summary
For more information about how to display a summary of the rules that were executed in a transaction and how to obtain the rules summary, see Transaction Summary.
View Errors in the Response
Functions, JavaScript libraries, request/response events, and rules can throw errors. You can identify the source of these errors in the error message that is included in responses that return HTTP 500 status codes.
The following code snippet shows an example of an error message in the response that the
MyFunction
function throws:
errorMessage": "Error while executing Resource JavaScript API-level function MyFunction - line 18: ReferenceError: \"ConfigLib2\" is not defined in
FU2031-MyFunction
at line number 18"
The following table lists the sources of error messages and the format in which they display:
Source
Format
Functions
FU###-[Function name]
JavaScript libraries
LI###-[Library name]
Request/response events
RQ###-[Request/response name]
Rules
RU###-[Rule name]
Call your API using Other HTTP Client Tools
You can view examples of how to include the authentication token and call your API from common HTTP client tools, on the
Request
tab, on the
Request
pane toolbar, click
How to call this API
.