Code Samples #
Copy
curl --request POST \
--url 'https://petstore.example.com/v1/pets' \
--header 'Content-Type: application/json' \
--data '{
"name": "Mochi",
"tag": "cat"
}'
const response = await fetch('https://petstore.example.com/v1/pets', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"name": "Mochi",
"tag": "cat"
})
});
const data = await response.json();
console.log(data);
import requests
headers = {
"Content-Type": "application/json"
}
payload = {
"name": "Mochi",
"tag": "cat"
}
response = requests.post("https://petstore.example.com/v1/pets", headers=headers, json=payload)
print(response.json())
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://petstore.example.com/v1/pets',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => [
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => '{
"name": "Mochi",
"tag": "cat"
}',
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
using System.Net.Http;
using System.Text;
var client = new HttpClient();
var request = new HttpRequestMessage(new HttpMethod("POST"), "https://petstore.example.com/v1/pets");
request.Content = new StringContent(@"{
""name"": ""Mochi"",
""tag"": ""cat""
}", Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
import java.net.URI;
import java.net.http.*;
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://petstore.example.com/v1/pets"))
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("""
{
"name": "Mochi",
"tag": "cat"
}
"""))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
Response #
Copy
{
"name": "Mochi",
"tag": "cat",
"id": 1
}
{
"code": 1,
"message": "string",
"fields": [
"string"
]
}
Request Body #
Content type: application/json — required
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Required | |
tag | string | Optional |
Example request
Copy
{
"name": "Mochi",
"tag": "cat"
}
Responses #
201 — Pet created #
| Field | Type | Required | Description |
|---|---|---|---|
name | string | Required | |
tag | string | Optional | |
id | integer (int64) | Required |
Example 201 response
Copy
{
"name": "Mochi",
"tag": "cat",
"id": 1
}
422 — Validation failed #
| Field | Type | Required | Description |
|---|---|---|---|
code | integer | Required | |
message | string | Required | |
fields | array of string | Optional |
Example 422 response
Copy
{
"code": 1,
"message": "string",
"fields": [
"string"
]
}
