API Testing Examples

Here are some API testing examples.

Basic Example

This is a simple example using a REST Request to access a URL and return a status.

  1. Click Create New to create a new API test.

  2. Name your test.

  3. Drag the REST Request building block from the building blocks pane into the workspace.

  4. Expand the block.

  5. Enter a URL that can be accessed using a REST API. For this example a URL from Wikipedia will be used as an example. https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch=chicago&format=json

    This URL returns Wikipedia’s articles that contain the word “Chicago” in their titles, using JSON as format.

    This is the outcome if you post the URL into a browser:

    Copy
    {"batchcomplete":"","continue":{"sroffset":10,"continue":"-||"},
    "query":{"searchinfo":{"totalhits":298598},"search":[{"ns":0,"title":
    "Chicago","pageid":6886,"size":257707,"wordcount":24058,"snippet":"
    <span class=\"searchmatch\">Chicago</span> (/\u0283\u026a\u02c8k\u0251\
    u02d0\u0261o\u028a/ (listen) shih-KAH-goh, locally also /\u0283\u026a
    \u02c8k\u0254\u02d0\u0261o\u028a/ shih-KAW-goh; Miami-Illinois: 
    Shikaakwa; Ojibwe: Zhigaagong) is the most populous","timestamp":
    "2023-06-15T18:42:28Z"},{"ns":0,"title":"University of Chicago",
    "pageid":32127,"size":152396,"wordcount":13166,"snippet":"of 
    <span class=\"searchmatch\">Chicago</span> (UChicago, <span
    class=\"searchmatch\">Chicago</span>, U of C, or UChi) is a 
    private research university in <span class=\"searchmatch\">C
    hicago</span>, Illinois. The university has its main campus in 
    <span class=\"searchmatch\">Chicago</span>'s","timestamp":
    "2023-06-12T11:41:53Z"},{"ns":0,"title":"Chicago Bulls",
    "pageid":72866,"size":136792,"wordcount":15418,"snippet":
    "The <span class=\"searchmatch\">Chicago</span> Bulls are an 
    American professional basketball team based in <span class=\
    "searchmatch\">Chicago</span>. The Bulls compete in the 
    National Basketball Association (NBA) as a member","timestamp":
    "2023-06-15T14:28:27Z"},{"ns":0,"title":"Chicago Bears","pageid"
    :6611,"size":153206,"wordcount":12362,"snippet":"The <span 
    class=\"searchmatch\">Chicago</span> Bears are a professional 
    American football team based in <span class=\"searchmatch\">Chicago
    </span>. The Bears compete in the National Football League (NFL)
    as a member club","timestamp":"2023-05-16T20:41:21Z"},{"ns":0,
    "title":"Chicago Tribune","pageid":60961,"size":102288,"wordcount"
    :10369,"snippet":"The <span class=\"searchmatch\">Chicago</span> 
    Tribune is a daily newspaper based in <span class=\"searchmatch\">
    Chicago</span>, Illinois, United States, owned by Tribune Publishing.
    Founded in 1847, and formerly self-styled","timestamp":
    "2023-06-16T02:02:49Z"},{"ns":0,"title":"Chicago metropolitan area",
    "pageid":326456,"size":65210,"wordcount":4827,"snippet":"The 
    <span class=\"searchmatch\">Chicago</span> metropolitan area, 
    also colloquially referred to as Chicagoland, is the metropolitan 
    area of the City of <span class=\"searchmatch\">Chicago</span>
    which includes its surrounding","timestamp":"2023-06-06T20:03:02Z"},
    {"ns":0,"title":"Chicago Fire","pageid":245768,"size":1007,
    "wordcount":156,"snippet":"<span class=\"searchmatch\">Chicago</span>
    Fire may refer to: Great <span class=\"searchmatch\">Chicago</span> 
    Fire, the fire that burned much of <span class=\"searchmatch\">
    Chicago</span> in 1871 Iroquois Theatre fire, a fire at a movie 
    theater in 1903 Chicago","timestamp":"2023-02-25T19:49:22Z"},
    {"ns":0,"title":"Chicago (band)","pageid":168876,"size":231522,
    "wordcount":18074,"snippet":"<span class=\"searchmatch\">
    Chicago</span> is an American rock band formed in <span class=\
    "searchmatch\">Chicago</span>, Illinois, in 1967. The group began 
    calling themselves the <span class=\"searchmatch\">Chicago</span> 
    Transit Authority in 1968, then","timestamp":"2023-06-12T23:43:23Z"},
    {"ns":0,"title":"Chicago Cubs","pageid":6654,"size":182209,"wordcount"
    :17364,"snippet":"The <span class=\"searchmatch\">Chicago</span> 
    Cubs are an American professional baseball team based in <span 
    class=\"searchmatch\">Chicago</span>. The Cubs compete in Major 
    League Baseball (MLB) as part of the National League","timestamp":
    "2023-06-05T23:00:42Z"},{"ns":0,"title":"South Chicago, Chicago",
    "pageid":1422349,"size":28907,"wordcount":2873,"snippet":"South 
    <span class=\"searchmatch\">Chicago</span>, formerly known as 
    Ainsworth, is one of the 77 community areas of <span class=\
    "searchmatch\">Chicago</span>, Illinois. This chevron-shaped 
    community is one of <span class=\"searchmatch\">Chicago</span>'s
    16","timestamp":"2023-04-24T09:10:11Z"}]}}

  6. Click the Run icon(). The result you see in the workspace should be Returns HTML Status Code 200 (Successful).

 

Basic Example with More Parameters

And, being already here, why not providing a few parameters?

  1. In the URL rthe user should replace &search=Chicago to &search={name}( The curly brackets or braces are necessary)

  2. The new URL should look like this: https://en.wikipedia.org/w/api.php?action=query&list=search&srsearch={name}&format=json

  3. The user then will be able to see how the {name} parameter appears:

  4. In the parameter value box, the name of an article or any word can be provided; for this example “Chicago” was used.

  5. Now is the time to click the “RUN” Button (located in the top corner of the workspace) or the smaller one located at the right side of the URL.

  6. Once the button is clicked, the “Waiting for response” message in the lower part of the block appears.

  7. This message will change to:

  8. Click the “Object” link, the output of the request will be displayed (in a more neat format than the one shown by just clicking on the link)

 

Example of a Nested Query

And… What happens if we want to create the equivalent of a nested Query? or perform a second filter on the results of the first?

  1. Minimize the “REST REQUEST” block with the Chevron located at the left side of the Block’s name (just to get more space to work) and add a “LOOP” Block.

  • Click the ”Select Object” box and confirm it is calling the “Response1.Query.Search” that you see in the first REST REQUEST.

NOTE: These values are being provided by the REST REQUEST

  • Expand it using the button with the Chevron “V” and add ANOTHER REST REQUEST. it is easier to close (minimize) the blocks before adding a new one

Use this URL:

https://en.wikipedia.org/w/api.php?action=query&titles={title}&prop=contributors&format=json

(This URL will receive the article title returned by the first request and return the collaborators and contributors for the specific article)

And the value: response1.query.search[0].title from the dropdown list

  • If needed, a VALIDATION Block can be added, this one checks that the output corresponds to what is expected, in this case no empty answers the source for this is: (response2.query.pages).

  • Once again, this can be RUN or Executed, and if there are no errors there are 2 parts that need to be checked.

The return from the second REST REQUEST block.

The Console.

  • If the user clicks on the “Show Console” Link (and of course, all went well) this is what should be seen:

NOTE: In case the testing requires values to be read from SQL queries or DPL that also can be done with the DATA FILE BLOCK.

or SQL block.

Verify that the access to the repository is working is as required. See Repository Configuration in Appvance IQ for more information.

Select the “OPEN” button.

If the user have the access, and the files, should be able to see the contents.