Create a pet
POST
/petsBody application/json
namestringrequired
tagstring
Response
Created
namestring
tagstring
idstring
/petsCreated
curl -X POST "https://petstore.swagger.io/v2/pets" \
-H "Content-Type: application/json" \
-H "X-API-Key: <X-API-Key>" \
-d '{
"name": "Rex",
"tag": "dog"
}'const response = await fetch(`https://petstore.swagger.io/v2/pets`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': '<X-API-Key>' },
body: JSON.stringify({
"name": "Rex",
"tag": "dog"
})
});
const data = await response.json();import requests
response = requests.request(
"POST",
"https://petstore.swagger.io/v2/pets",
headers={ "X-API-Key": "<X-API-Key>" },
json={
"name": "Rex",
"tag": "dog"
},
)
data = response.json()<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://petstore.swagger.io/v2/pets");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json", "X-API-Key: <X-API-Key>"]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"name": "Rex",
"tag": "dog"
}');
$response = curl_exec($ch);
curl_close($ch);package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
req, _ := http.NewRequest("POST", "https://petstore.swagger.io/v2/pets", strings.NewReader(`{
"name": "Rex",
"tag": "dog"
}`))
req.Header.Set("Content-Type", "application/json")
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"))
.header("Content-Type", "application/json")
.header("X-API-Key", "<X-API-Key>")
.method("POST", HttpRequest.BodyPublishers.ofString("{\n \"name\": \"Rex\",\n \"tag\": \"dog\"\n}"))
.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")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request["X-API-Key"] = "<X-API-Key>"
request.body = "{\n \"name\": \"Rex\",\n \"tag\": \"dog\"\n}"
response = http.request(request)
puts response.body{
"name": "Rex",
"tag": "dog",
"id": "abc123"
}curl -X POST "https://petstore.swagger.io/v2/pets" \
-H "Content-Type: application/json" \
-H "X-API-Key: <X-API-Key>" \
-d '{
"name": "Rex",
"tag": "dog"
}'const response = await fetch(`https://petstore.swagger.io/v2/pets`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-API-Key': '<X-API-Key>' },
body: JSON.stringify({
"name": "Rex",
"tag": "dog"
})
});
const data = await response.json();import requests
response = requests.request(
"POST",
"https://petstore.swagger.io/v2/pets",
headers={ "X-API-Key": "<X-API-Key>" },
json={
"name": "Rex",
"tag": "dog"
},
)
data = response.json()<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://petstore.swagger.io/v2/pets");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json", "X-API-Key: <X-API-Key>"]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{
"name": "Rex",
"tag": "dog"
}');
$response = curl_exec($ch);
curl_close($ch);package main
import (
"fmt"
"io"
"net/http"
"strings"
)
func main() {
req, _ := http.NewRequest("POST", "https://petstore.swagger.io/v2/pets", strings.NewReader(`{
"name": "Rex",
"tag": "dog"
}`))
req.Header.Set("Content-Type", "application/json")
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"))
.header("Content-Type", "application/json")
.header("X-API-Key", "<X-API-Key>")
.method("POST", HttpRequest.BodyPublishers.ofString("{\n \"name\": \"Rex\",\n \"tag\": \"dog\"\n}"))
.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")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
request = Net::HTTP::Post.new(uri)
request["Content-Type"] = "application/json"
request["X-API-Key"] = "<X-API-Key>"
request.body = "{\n \"name\": \"Rex\",\n \"tag\": \"dog\"\n}"
response = http.request(request)
puts response.body