NAV Navigation
Shell HTTP JavaScript Node.js Ruby Python Java Go PHP

Swagger Petstore v1.0.0

Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.

A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification

Base URLs:

Terms of service Email: Swagger API Team Web: Swagger API Team License: Apache 2.0

Default

findPets

Code samples

# You can also use wget
curl -X GET http://petstore.swagger.io/api/pets \
  -H 'Accept: application/json'

GET http://petstore.swagger.io/api/pets HTTP/1.1
Host: petstore.swagger.io
Accept: application/json


const headers = {
  'Accept':'application/json'
};

fetch('http://petstore.swagger.io/api/pets',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

const fetch = require('node-fetch');

const headers = {
  'Accept':'application/json'
};

fetch('http://petstore.swagger.io/api/pets',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get 'http://petstore.swagger.io/api/pets',
  params: {
  }, headers: headers

p JSON.parse(result)

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('http://petstore.swagger.io/api/pets', headers = headers)

print(r.json())

URL obj = new URL("http://petstore.swagger.io/api/pets");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());

package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("GET", "http://petstore.swagger.io/api/pets", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('GET','http://petstore.swagger.io/api/pets', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...

GET /pets

Returns all pets from the system that the user has access to Nam sed condimentum est. Maecenas tempor sagittis sapien, nec rhoncus sem sagittis sit amet. Aenean at gravida augue, ac iaculis sem. Curabitur odio lorem, ornare eget elementum nec, cursus id lectus. Duis mi turpis, pulvinar ac eros ac, tincidunt varius justo. In hac habitasse platea dictumst. Integer at adipiscing ante, a sagittis ligula. Aenean pharetra tempor ante molestie imperdiet. Vivamus id aliquam diam. Cras quis velit non tortor eleifend sagittis. Praesent at enim pharetra urna volutpat venenatis eget eget mauris. In eleifend fermentum facilisis. Praesent enim enim, gravida ac sodales sed, placerat id erat. Suspendisse lacus dolor, consectetur non augue vel, vehicula interdum libero. Morbi euismod sagittis libero sed lacinia.

Sed tempus felis lobortis leo pulvinar rutrum. Nam mattis velit nisl, eu condimentum ligula luctus nec. Phasellus semper velit eget aliquet faucibus. In a mattis elit. Phasellus vel urna viverra, condimentum lorem id, rhoncus nibh. Ut pellentesque posuere elementum. Sed a varius odio. Morbi rhoncus ligula libero, vel eleifend nunc tristique vitae. Fusce et sem dui. Aenean nec scelerisque tortor. Fusce malesuada accumsan magna vel tempus. Quisque mollis felis eu dolor tristique, sit amet auctor felis gravida. Sed libero lorem, molestie sed nisl in, accumsan tempor nisi. Fusce sollicitudin massa ut lacinia mattis. Sed vel eleifend lorem. Pellentesque vitae felis pretium, pulvinar elit eu, euismod sapien.

Parameters

Name In Type Required Description
tags query array[string] false tags to filter by
limit query integer(int32) false maximum number of results to return

Example responses

200 Response

[
  null
]

Responses

Status Meaning Description Schema
200 OK pet response Inline
default Default unexpected error Error

Response Schema

Status Code 200

Name Type Required Restrictions Description
anonymous [allOf] false none none

allOf

Name Type Required Restrictions Description
» anonymous object false none none
»» name string true none none
»» tag string false none none

and

Name Type Required Restrictions Description
» anonymous object false none none
»» id integer(int64) true none none

addPet

Code samples

# You can also use wget
curl -X POST http://petstore.swagger.io/api/pets \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json'

POST http://petstore.swagger.io/api/pets HTTP/1.1
Host: petstore.swagger.io
Content-Type: application/json
Accept: application/json

const inputBody = '{
  "name": "string",
  "tag": "string"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json'
};

fetch('http://petstore.swagger.io/api/pets',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

const fetch = require('node-fetch');
const inputBody = {
  "name": "string",
  "tag": "string"
};
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json'
};

fetch('http://petstore.swagger.io/api/pets',
{
  method: 'POST',
  body: JSON.stringify(inputBody),
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

require 'rest-client'
require 'json'

headers = {
  'Content-Type' => 'application/json',
  'Accept' => 'application/json'
}

result = RestClient.post 'http://petstore.swagger.io/api/pets',
  params: {
  }, headers: headers

p JSON.parse(result)

import requests
headers = {
  'Content-Type': 'application/json',
  'Accept': 'application/json'
}

r = requests.post('http://petstore.swagger.io/api/pets', headers = headers)

print(r.json())

URL obj = new URL("http://petstore.swagger.io/api/pets");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());

package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Content-Type": []string{"application/json"},
        "Accept": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("POST", "http://petstore.swagger.io/api/pets", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

 'application/json',
    'Accept' => 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('POST','http://petstore.swagger.io/api/pets', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...

POST /pets

Creates a new pet in the store. Duplicates are allowed

Body parameter

{
  "name": "string",
  "tag": "string"
}

Parameters

Name In Type Required Description
body body NewPet true Pet to add to the store

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK pet response Pet
default Default unexpected error Error

find pet by id

Code samples

# You can also use wget
curl -X GET http://petstore.swagger.io/api/pets/{id} \
  -H 'Accept: application/json'

GET http://petstore.swagger.io/api/pets/{id} HTTP/1.1
Host: petstore.swagger.io
Accept: application/json


const headers = {
  'Accept':'application/json'
};

fetch('http://petstore.swagger.io/api/pets/{id}',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

const fetch = require('node-fetch');

const headers = {
  'Accept':'application/json'
};

fetch('http://petstore.swagger.io/api/pets/{id}',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.get 'http://petstore.swagger.io/api/pets/{id}',
  params: {
  }, headers: headers

p JSON.parse(result)

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.get('http://petstore.swagger.io/api/pets/{id}', headers = headers)

print(r.json())

URL obj = new URL("http://petstore.swagger.io/api/pets/{id}");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());

package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("GET", "http://petstore.swagger.io/api/pets/{id}", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('GET','http://petstore.swagger.io/api/pets/{id}', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...

GET /pets/{id}

Returns a user based on a single ID, if the user does not have access to the pet

Parameters

Name In Type Required Description
id path integer(int64) true ID of pet to fetch

Example responses

200 Response

null

Responses

Status Meaning Description Schema
200 OK pet response Pet
default Default unexpected error Error

deletePet

Code samples

# You can also use wget
curl -X DELETE http://petstore.swagger.io/api/pets/{id} \
  -H 'Accept: application/json'

DELETE http://petstore.swagger.io/api/pets/{id} HTTP/1.1
Host: petstore.swagger.io
Accept: application/json


const headers = {
  'Accept':'application/json'
};

fetch('http://petstore.swagger.io/api/pets/{id}',
{
  method: 'DELETE',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

const fetch = require('node-fetch');

const headers = {
  'Accept':'application/json'
};

fetch('http://petstore.swagger.io/api/pets/{id}',
{
  method: 'DELETE',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

require 'rest-client'
require 'json'

headers = {
  'Accept' => 'application/json'
}

result = RestClient.delete 'http://petstore.swagger.io/api/pets/{id}',
  params: {
  }, headers: headers

p JSON.parse(result)

import requests
headers = {
  'Accept': 'application/json'
}

r = requests.delete('http://petstore.swagger.io/api/pets/{id}', headers = headers)

print(r.json())

URL obj = new URL("http://petstore.swagger.io/api/pets/{id}");
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("DELETE");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
    new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();
System.out.println(response.toString());

package main

import (
       "bytes"
       "net/http"
)

func main() {

    headers := map[string][]string{
        "Accept": []string{"application/json"},
    }

    data := bytes.NewBuffer([]byte{jsonReq})
    req, err := http.NewRequest("DELETE", "http://petstore.swagger.io/api/pets/{id}", data)
    req.Header = headers

    client := &http.Client{}
    resp, err := client.Do(req)
    // ...
}

 'application/json',
);

$client = new \GuzzleHttp\Client();

// Define array of request body.
$request_body = array();

try {
    $response = $client->request('DELETE','http://petstore.swagger.io/api/pets/{id}', array(
        'headers' => $headers,
        'json' => $request_body,
       )
    );
    print_r($response->getBody()->getContents());
 }
 catch (\GuzzleHttp\Exception\BadResponseException $e) {
    // handle exception or api errors.
    print_r($e->getMessage());
 }

 // ...

DELETE /pets/{id}

deletes a single pet based on the ID supplied

Parameters

Name In Type Required Description
id path integer(int64) true ID of pet to delete

Example responses

default Response

{
  "code": 0,
  "message": "string"
}

Responses

Status Meaning Description Schema
204 No Content pet deleted None
default Default unexpected error Error

Schemas

Pet

null

Properties

allOf

Name Type Required Restrictions Description
anonymous NewPet false none none

and

Name Type Required Restrictions Description
anonymous object false none none
» id integer(int64) true none none

NewPet

{
  "name": "string",
  "tag": "string"
}

Properties

Name Type Required Restrictions Description
name string true none none
tag string false none none

Error

{
  "code": 0,
  "message": "string"
}

Properties

Name Type Required Restrictions Description
code integer(int32) true none none
message string true none none