What is a Request Body in an API?
In many APIs—especially those that create or update data—the most important part of the request is the request body. Unlike query or path parameters (which go in the URL), the request body is where you send structured data, usually as JSON.In this article, we’ll explain what a request body is, when to use it, and how to read the body specification in API docs. We’ll use the Petstore API to demonstrate.
1. What Is a Request Body?#
A request body is data you send inside the HTTP request, typically used with:POST (create a new resource)
PATCH (update part of a resource)
Most GET requests do not have a body.The request body is usually formatted in JSON, but some APIs support:Form data (multipart/form-data for files)
But JSON is the modern standard.Unlike query parameters or headers, the body can hold complex structured data, such as nested objects, arrays, files, or binary content.
1. Schema: What Shape of Data Should You Send?#
Before you write a request body, you must understand the schema that describes the expected structure.The documentation shows the schema for a Pet object:Which fields exist (id, name, category, etc.)
The types (number, string, array, object)
The nested structure (category and tags are objects/arrays of objects)
The allowed values (e.g., status might be "available" | "pending" | "sold")
Every request body you send must follow this shape.
2. JSON Body — the Most Common Format#
Most modern REST APIs expect JSON.
Using the above schema, here is a valid JSON request body for POST /pets:{
"name": "Lucky",
"species": "DOG",
"breed": "Golden Retriever",
"ageMonths": 24,
"size": "LARGE",
"color": "Golden",
"gender": "MALE",
"goodWithKids": true,
"goodWithPets": true,
"adoptionFee": 150.00,
"description": "Friendly golden retriever looking for an active family",
"status": "AVAILABLE"
}
In Apidog, when you need to create a request body based on the body schema, you can use Apidog’s Auto-generate feature to generate a body that matches the schema.When to use JSON?#
Creating or updating objects
Sending structured data (objects, arrays)
Most API clients and servers support it automatically
When sending JSON as the body, the Content-Type header should be set to application/json; however, most tools handle this automatically, so you usually don’t need to worry about it.
3. XML Body — Less Common but Still Used in Some APIs#
Some older APIs (or enterprise APIs) support XML.
Using the same schema, the body can also be written as XML:<Pet>
<id>123</id>
<name>Lucky</name>
<category>
<id>1</id>
<name>Dog</name>
</category>
<photoUrls>
<photoUrl>https://example.com/dog.jpg</photoUrl>
</photoUrls>
<tags>
<tag>
<id>10</id>
<name>friendly</name>
</tag>
</tags>
<status>available</status>
</Pet>
You would set the Content-Type: application/xml header if you’re sending XML.
Some endpoints accept files, such as images.
In these cases, JSON is not enough — you must use multipart/form-data.The documentation tells you the body consists of:| Field | Type | Description |
|---|
| file | binary | The image to upload |
| additionalMetadata | string | (optional) Extra info |
You can click "Upload" in the file field to upload the binary file.Uploading images, PDFs, videos
Mixed content: text + file
Browser-based form submissions
5. Key Takeaways#
Here’s what you should remember about request bodies:The schema tells you what shape and fields your body must follow
JSON is the most common request-body format
XML is still supported in some APIs
multipart/form-data is required for file uploads
Always match the right Content-Type
This tells the server how to interpret your body.
Now that you understand what a request body is, how schemas define its structure, and how different formats like JSON, XML, and multipart/form-data are used, you’re ready for the next step: learning how to read and interpret the Response that the server sends back. Modified at 2025-12-25 09:31:00