Get a pet by ID
GET
/pets/{petId}Path Parameters
petIdstringrequired
The pet's unique ID
Response
A pet
namestring
tagstring
idstring
Pet not found
errorstring
/pets/{petId}The pet's unique ID
A pet
Pet not found
curl -X GET "https://petstore.swagger.io/v2/pets/<petId>" \
-H "X-API-Key: <X-API-Key>"const response = await fetch(`https://petstore.swagger.io/v2/pets/${petId}`, {
method: 'GET',
headers: { 'X-API-Key': '<X-API-Key>' }
});
const data = await response.json();import requests
response = requests.request(
"GET",
"https://petstore.swagger.io/v2/pets/{petId}",
headers={ "X-API-Key": "<X-API-Key>" },
)
data = response.json()<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://petstore.swagger.io/v2/pets/<petId>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: <X-API-Key>"]);
$response = curl_exec($ch);
curl_close($ch);package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://petstore.swagger.io/v2/pets/<petId>", nil)
req.Header.Set("X-API-Key", "<X-API-Key>")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(string(data))
}HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://petstore.swagger.io/v2/pets/<petId>"))
.header("X-API-Key", "<X-API-Key>")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());require "net/http"
require "uri"
uri = URI("https://petstore.swagger.io/v2/pets/<petId>")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
request = Net::HTTP::Get.new(uri)
request["X-API-Key"] = "<X-API-Key>"
response = http.request(request)
puts response.body{
"name": "Rex",
"tag": "dog",
"id": "abc123"
}{
"error": "Pet not found"
}curl -X GET "https://petstore.swagger.io/v2/pets/<petId>" \
-H "X-API-Key: <X-API-Key>"const response = await fetch(`https://petstore.swagger.io/v2/pets/${petId}`, {
method: 'GET',
headers: { 'X-API-Key': '<X-API-Key>' }
});
const data = await response.json();import requests
response = requests.request(
"GET",
"https://petstore.swagger.io/v2/pets/{petId}",
headers={ "X-API-Key": "<X-API-Key>" },
)
data = response.json()<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://petstore.swagger.io/v2/pets/<petId>");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-API-Key: <X-API-Key>"]);
$response = curl_exec($ch);
curl_close($ch);package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://petstore.swagger.io/v2/pets/<petId>", nil)
req.Header.Set("X-API-Key", "<X-API-Key>")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
data, _ := io.ReadAll(resp.Body)
fmt.Println(string(data))
}HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://petstore.swagger.io/v2/pets/<petId>"))
.header("X-API-Key", "<X-API-Key>")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());require "net/http"
require "uri"
uri = URI("https://petstore.swagger.io/v2/pets/<petId>")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
request = Net::HTTP::Get.new(uri)
request["X-API-Key"] = "<X-API-Key>"
response = http.request(request)
puts response.body