Exploring REST APIs

Last modified on February 14, 2023

This tutorial will walk you through a simple REST example: retrieving data, creating data with a PUT operation, retrieving your new data and finally deleting the data.

Requirements

To complete this tutorial, you need:

Trying out the Petstore API

Let's begin by looking at the operations allowed by the public Petstore API that is available through swagger.io. Here are the operations that are available:

The main screen of API Exploration

When you are logged in to API Exploration you will see the main screen. From here, you can enter API operations and see the return values.

Click the image to enlarge it.

Storing data with PUT

Let's add a new dog named Rex to the pet store. To do that, we need to:

  • Set the Operation to be POST
  • Paste the URL into the Server field:

    https://petstore3.swagger.io/api/v3/pet

  • Paste the following into the Body of the request to add a dog named Rex with ID=20:

    					
    {
      "id": 20,
      "name": "Rex",
      "category": {
        "id": 1,
        "name": "Dogs"
      },
      "photoUrls": [
        "string"
      ],
      "tags": [
        {
          "id": 0,
          "name": "string"
        }
      ],
      "status": "available"
    }					
    					
    				

Click the image to enlarge it.

Once you click Send, you will see the response to confirm that the dog was added:

Click the image to enlarge it.

Retrieving data with GET

Let's do a query now to confirm that our dog was added. To do that, we need to:

  • Perform a GET operation
  • Add the {petid} parameter to the URL
  • Specify that the record with ID 20 should be retrieved, either by typing it in the Path field or by entering the data into the Headers & Parameters table.

Click the image to enlarge it.

When you click Send you will see the response confirming that the data is there:

Click the image to enlarge it.

This is a public test API -- data that is added here is deleted on a regular basis, so you can't count on data remaining here for long periods.
Deleting data with a DELETE operation

To delete the dog Rex with ID 20 we will do the following:

  • Perform a DELETE operation

Click the image to enlarge it.

After you click Send, the results will be displayed:

Highlight search results