Build an API test from an existing web application.
A web app is usually composed of a frontend and a backend. The backend exposes a REST API
which is used by the frontend to consume data.
When developing new features on a web app, backend developers want to make sure they do not
break existing APIs. Frontend developers, on their side, want a reliable API to build their UI
layer on. This way they can focus on what really matters: designing a good user
experience.
This is where API tests bring value. API tests help development teams to ensure they do
not break the API contract when making changes in the application code.
Procedure
-
Open your web app in your browser.
-
Open the browser's developer tools and select the
Network tab.
This tutorial is illustrated by screenshots of a web and mobile app that allows users to browse Quentin Tarantino's filmography.
-
Use your web app and reproduce a user's sequence of actions.
Your web app’s frontend will call the backend API as you navigate through the different screens.
You can see requests being sent in the browser’s
Network tab.
-
Save or copy these network exchanges in HAR format.
HAR (HTTP Archive) is a JSON-based archive file aimed at storing a web
browser’s network interaction.
-
Open Talend Cloud API Tester and go to .
-
Upload your .har file and select the requests to be included in your API test,
then click Import.
Filtering capabilities can be used to hide requests that do not target the
backend API you want to test (such as images, CSS, Javascript...).
-
Select the project in which you want to save your requests or create a new one
by clicking .
-
Click to save this sequence of requests into a scenario.
In Talend Cloud API Tester, a scenario
is an ordered sequence of requests that closely emulates real-life use of
the API.
-
Name your scenario and click Add, then click
Save.
-
Run your scenario to see the requests sent by Talend Cloud API Tester.
-
Add assertions to your scenario.
Assertions will ensure your API is behaving as expected.
A good starting point is to check the response status code
(for example you can usually expect a 200 status code for a GET request).
You can then go further by creating assertions on response headers and body. For
more information, see Assertions.