Explore REST APIs

This tutorial demonstrates how to explore a REST example in SwaggerHub Explore. You’ll learn to do the following:

  • Retrieve data.

  • Create data with a PUT operation.

  • Retrieve your new data.

  • Delete the data you created.

Requirements

To complete this tutorial, you need:

Petstore API Example

Let's begin by looking at the operations allowed by the public Petstore API. This is available through swagger.io. Here are the available operations for working with pets in the store:

petstore-api-doc.png

In this tutorial, you enter these API operations into SwaggerHub Explore. For each of these operations, SwaggerHub Explore returns values.

Use a POST operation with SwaggerHub Explore

Let's add a new dog named Rex, with an ID value of 20 to the pet store. Do the following:

  1. From the Operation menu, select POST.

  2. In the Server field, paste the following URL:

    https://petstore3.swagger.io/api/v3/pet
    
  3. Click Body, and paste the following request into the Body field

                                         
    {
      "id": 20,
      "name": "Rex",
      "category": {
        "id": 1,
        "name": "Dogs"
      },
      "photoUrls": [
        "string"
      ],
      "tags": [
        {
          "id": 0,
          "name": "string"
        }
      ],
      "status": "available"
    }                                       
                                            
                                    
  4. Click Send. SwaggerHub Explore displays a response to confirm that the addition was successful.

Use a GET operation with SwaggerHub Explore

Let's confirm that you added Rex to the pet store. Do the following:

  • From the Operation menu, select GET.

  • In the Path field, append the following string (parameter): /{petid}

  • In the Headers & Parameters table, click on the petid line and type Rex’s ID value, 20, in the Value column. This sets the petid parameter and specifies to retrieve the record with an ID value of 20.

  • Click Send. SwaggerHub Explore displays a response to confirm that the data you added is in the pet store.

Important

This is a public test API. Data added to public test APIs is deleted regularly. Data may not remain here for long periods.

Use a DELETE operation with SwaggerHub Explore

Let’s delete Rex from the pet store. Do the following:

  • From the Operation menu, select DELETE. All of the other settings (path and parameters) are already set correctly.

  • Click Send. SwaggerHub Explore displays a response to confirm that You have deleted Rex from the pet store.

Publication date: