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.
-
Start the local test servers by completing the following steps:
-
In the API Designer, click Run.
-
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.
-
Wait until the
Running
message is displayed.
-
Start the local test servers.In the test console at the bottom of the screen, click the Start the servers icon:
A completed service start displays Running next to the gateway type, URL, and the port where it is available. 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 to start again with the new settings.
-
Click the APIs tab.
-
Click the name of the API that you want to test.
-
Click the Assemble tab.
-
Click the Test icon .
- Choose the Operation (endpoint) to test.
-
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.
- Optional:
If you want to run the test multiple times, complete the following steps:
-
Select the Repeat check box.
-
Use the Stop after field to specify how many times to run the
test.
-
If you want the test to stop when an error occurs, select the Stop on
error check box.
-
Click Invoke.
The test result is displayed in the Response section. You can continue to test different
field values as necessary.
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
. 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.