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:
-
Access to API Exploration (click here if you need help with that).
-
Basic knowledge of REST APIs.
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.
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" }
Once you click Send, you will see the response to confirm that the dog was added:
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.
When you click Send you will see the response confirming that the data is there:
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
After you click Send, the results will be displayed: