Testing an API with the API Designer test tool

Even while you are working offline, you can test the API to ensure that is defined and implemented correctly.

About this task

The API Designer user interface has an integrated test tool. During the test, the API is hosted on a local gateway.

Procedure

To test an API, complete the following steps.

  1. [V5.0.0 only] Start the local test servers by completing the following steps:
    1. In the API Designer, click Run.
    2. Click Start to run your Micro Gateway locally and host your APIs on it. A node.exe window opens when your Micro Gateway is running; leave the window open until you are finished testing API.
      Note: If your Micro Gateway is already running, you must restart it before you can test your changes, by clicking Restart.
    3. Wait until the Running message is displayed.
  2. [V5.0.1 or later] Start the local test servers.In the test console at the bottom of the screen, click the Start the servers icon:
    Start the servers icon
    A completed service start displays Running next to the gateway type, URL, and the port where it is available.
    Running
    Your project configuration and other running processes can produce a different gateway type, URL, or port number than is displayed in the image.
    Test changes that are for a running gateway by clicking the Restart the servers icon
    Restart the servers icon
    to start again with the new settings.
  3. Click the APIs tab.
  4. Click the name of the API that you want to test.
  5. Click the Assemble tab.
  6. Click the Test icon The Test icon.
  7. Choose the Operation (endpoint) to test.
  8. Provide values for the parameters you set in your operation with the Parameters section of the test tool, or click Generate to create random values based on the data type that is set for each parameter.
    Note: The test tool does not enforce the required setting for any parameters in the definition of the operation.
  9. Optional: If you want to run the test multiple times, complete the following steps:
    1. Select the Repeat check box.
    2. Use the Stop after field to specify how many times to run the test.
    3. If you want the test to stop when an error occurs, select the Stop on error check box.
  10. Click Invoke.
    The test result is displayed in the Response section. You can continue to test different field values as necessary.
    [V5.0.8 or later]Note: Modern web browsers prevent local resources from being accessed by the API Designer, and display a CORS (cross origin resource sharing) alert on the page. To enable local API testing in CORS compliant browsers, select the Enable Proxy check box to send test messages from the local server that hosts API Designer rather than from the browser. The proxied request appears as in the example.
    Request URL: http://localhost:port/proxy/proxyService
    Request Method: POST
    Request Payload: The test content
    Responses are returned directly to the user interface. For more information about CORS, see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS.

Results

You successfully tested an API.
Note: You can also use the API Explore tool within API Designer to test API endpoints. Ensure that your local test servers are running, then click Explore. The API Explore tool opens, and shows the operations, definitions, and documentation for all of the APIs that are contained in your Drafts view. The left pane of the Explore window can be used to select an operation to test. The center pane displays summary information about the endpoint, including its parameters, model instance data, and response codes, and the right pane provides template code to call the endpoint.