Skip to content

issavejdani/pet-store-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

Introduction

Petstore APIs were designed and developed by John Smith as a hobby project. He created them on his weekends. One day he decided to make them open source by creating a public repository on Github. Then he used them to start a small business as they grew. This document covers the integration process required to use these APIs' "pet" section. You can add, remove, update, and retrieve pet data using these APIs.

API integration process

Take a look at this petstore.swagger.io to start integrating these APIs. It gives you a lot of information at a glance. You can even test every API by clicking on "Try it out" button.

try-out-button

POST Add a new pet

Endpoint /pet/
Sample url https://petstore.swagger.io/v2/pet/

Input Parameters

Name Description Required Type
body Pet object that needs to be added to the store true object

Example body

{
  "id": 0,
  "category": {
    "id": 0,
    "name": "string"
  },
  "name": "doggie",
  "photoUrls": [
    "string"
  ],
  "tags": [
    {
      "id": 0,
      "name": "string"
    }
  ],
  "status": "available"
}

Response

Status code Response
200 { "id": 9223372036854043000, "category": { "id": 0, "name": "string" }, "name": "doggie", "photoUrls": [ "string" ], "tags": [ { "id": 0, "name": "string" } ], "status": available"}
405 Invalid Input

GET Find a pet by ID

Endpoint /pet/{petId}
Sample url https://petstore.swagger.io/v2/pet/3341

Input Parameters

Name Description Required Type
petId ID of pet to return true string

Response

Status code Response
200 { "id": 0, "category": { "id": 0, "name": "string" }, "name": "doggie", "photoUrls": "string" ], "tags": [ { "id": 0, "name": "string" } ], "status": "available"}
400 Invalid ID supplied
400 Pet not found

DELETE Delete a pet by ID

Endpoint /pet/{petId}
Sample url https://petstore.swagger.io/v2/pet/3341

Input Parameters

Name Description Required Type Location
api_key The key you need to authorize yourself false string Header
petId Pet id to delete true string Querystring

For this sample, you can use the api key special-key to test the authorization filters.

Response

Status code Response
200 { "code": 200,"type": "unknown","message": "{petId}}"}
400 Invalid ID supplied
400 Pet not found

Sample Code

Using this piece of code in python, you can get a list of all pets base on their status. The status can be one of the followings:

  • Available
  • Pending
  • Sold

This code returns a list of 10 pets with unique names and available status

Setup and run

To run this code snippet, you need to install requests module by running the following command.

pip install requests 

Once you finish the installation process, save the code in a file named app.py and run it by running the following command.

python app.py 
import requests

response = requests.get("https://petstore.swagger.io/v2/pet/findByStatus?status=available")
pets = response.json()
uniqueNames = []
i = 0


while (len(uniqueNames)<=9):
    if(pets[i]['name'] not in uniqueNames):
        uniqueNames.append(pets[i]['name'])
        print(pets[i]['id'] , pets[i]['name'])
    i = i + 1    

About

To add, remove, and get a pet using these APIs.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published