Test APIs
APIs allow different software applications to communicate with each other and exchange information. In API testing, you send requests to the API and check the responses to ensure that everything works as expected.
Ready to test an API? You'll need one or more API messages. Each message has everything you need, including connection info, request data, verification steps, and authentication. Once you create a message, run it as a quick test or use it in your test cases.
Create an API message
Here's how to create an API message:
-
Go to API simulation > API playground.
-
Choose a clear name for your API message.
-
Set up your request:
-
Method - Choose how to send your request.
-
Endpoint - Add the URL for your API. Tosca Cloud currently supports HTTP and HTTPS.
-
Payload - Include the data you want to send.
-
Headers - If needed, add extra information, such as content type or custom fields.
-
Authorization - Enter basic authentication credentials if your service requires it.
-
-
Define a Verification for the response message, if you want to check that the expected value matches the actual value.
-
Run a quick test to see whether your entries are valid and the verification returns the expected value.
-
Select Save.
The Headers, Authorization, and Verification tabs show how many items you've added.
Find all your API messages in the API playground panel:
API playground
Set up verification
Verifications help you test whether your service works as expected. You can verify message format, content, or response codes. Just set the values you expect and compare them to what the service actually returns.
To set up verification:
-
Select an existing API message or create a new one.
-
In the Response section, select the Verification tab.
-
Select
to add a verification.
-
Select an entry of the newly created verification and edit the following properties:
-
Name - Give your verification a unique name.
-
Type - Choose what to verify: Header, JsonPath, XPath, StatusCode, or ResponseTime.
-
Expression - If you picked JsonPath or XPath, add your expression here.
-
Operator - Choose your comparison method. Possible operators are Equal, NotEqual, Smaller, LessOrEqual, Greater, or GreaterOrEqual.
-
Value - Enter the expected value.
-
-
Select Save.
This example uses XPath to check a calculation result.
Run a quick test
Want to test your API message right now? Here's how to run a quick one-time test:
-
Select an existing API message or create a new one.
-
Select Send
-
Check your results on the Response tab:
-
Status code - Shows if your message reached the API successfully.
-
Verification results - See if your verification passed, if you set any.
-
Response results
Create API test case from API message
To create an API test case, follow these steps:
-
Select an existing API message or create a new one.
-
Select Create API test case.
-
In the menu bar on the left, select Test cases to find your new API test case.
-
Select the API test case to open it in the test case editor to further design your test case.
Delete API messages
To delete an API message, go to API playground, select the message you want to remove, then select Delete.
This affects all test cases that currently use the API message. We recommend updating these test cases before you proceed, otherwise they will fail at runtime.
What's next
Learn how to create a simulation from your API message.