HTTP Request Body: Complete Guide (2026)
Understand request bodies, content types, and how to send data over HTTP
Start Building with Hypereal
Access Kling, Flux, Sora, Veo & more through a single API. Free credits to start, scale to millions.
No credit card required • 100k+ developers • Enterprise ready
HTTP Request Body: Complete Guide (2026)
The HTTP request body is the part of an HTTP request that carries the data you want to send to the server. Whether you are submitting a form, uploading a file, or calling an API, understanding request bodies is fundamental to web development and API integration.
This guide covers everything you need to know about HTTP request bodies: what they are, when to use them, which content types exist, and how to send them correctly using different tools and programming languages.
What Is an HTTP Request Body?
An HTTP request consists of three parts:
- Request line - The method (GET, POST, etc.) and the URL
- Headers - Metadata about the request
- Body - The actual data payload (optional)
The body is where you put the data you want to send to the server. Not all HTTP methods use a body.
Which HTTP Methods Use a Body?
| Method | Has Body | Common Use Case |
|---|---|---|
| GET | No (technically allowed but not recommended) | Retrieving data |
| POST | Yes | Creating resources, submitting data |
| PUT | Yes | Replacing a resource entirely |
| PATCH | Yes | Partially updating a resource |
| DELETE | Rarely (allowed but uncommon) | Deleting a resource |
| HEAD | No | Same as GET but no response body |
| OPTIONS | No | CORS preflight checks |
The Content-Type header tells the server what format the body is in. If you send a body without this header, the server may not know how to parse it.
Content Types Explained
The Content-Type header is critical when sending a request body. Here are the most common types:
1. application/json
The most common format for modern APIs. Data is sent as a JSON string.
Content-Type: application/json
{
"name": "Alice",
"email": "alice@example.com",
"age": 30
}
2. application/x-www-form-urlencoded
The default format for HTML form submissions. Data is encoded as key-value pairs separated by &.
Content-Type: application/x-www-form-urlencoded
name=Alice&email=alice%40example.com&age=30
Special characters are percent-encoded (e.g., @ becomes %40).
3. multipart/form-data
Used for file uploads and forms that include binary data. Each field is separated by a boundary string.
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="name"
Alice
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="avatar"; filename="photo.jpg"
Content-Type: image/jpeg
(binary data)
------WebKitFormBoundary7MA4YWxkTrZu0gW--
4. text/plain
Plain text with no special encoding.
Content-Type: text/plain
This is just plain text content.
5. application/xml
XML-formatted data, still common in enterprise APIs and SOAP services.
Content-Type: application/xml
<user>
<name>Alice</name>
<email>alice@example.com</email>
<age>30</age>
</user>
Content Type Comparison
| Content Type | Best For | Supports Files | Human Readable | Size |
|---|---|---|---|---|
| application/json | APIs | No (use base64) | Yes | Small-Medium |
| application/x-www-form-urlencoded | Simple forms | No | Somewhat | Small |
| multipart/form-data | File uploads | Yes | No | Any |
| text/plain | Raw text | No | Yes | Small-Medium |
| application/xml | Enterprise APIs | No (use base64) | Yes | Medium-Large |
Sending Request Bodies: Practical Examples
Using cURL
JSON body:
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com"}'
Form-encoded body:
curl -X POST https://api.example.com/users \
-d "name=Alice&email=alice@example.com"
cURL automatically sets Content-Type: application/x-www-form-urlencoded when using -d without specifying a content type.
File upload (multipart):
curl -X POST https://api.example.com/upload \
-F "file=@photo.jpg" \
-F "description=Profile photo"
The -F flag automatically sets the content type to multipart/form-data.
Reading body from a file:
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d @payload.json
Using JavaScript (fetch)
JSON body:
const response = await fetch('https://api.example.com/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Alice',
email: 'alice@example.com',
}),
});
const data = await response.json();
Form data:
const formData = new FormData();
formData.append('name', 'Alice');
formData.append('email', 'alice@example.com');
const response = await fetch('https://api.example.com/users', {
method: 'POST',
body: formData,
// Do NOT set Content-Type header - the browser sets it automatically
// with the correct boundary for multipart/form-data
});
File upload:
const fileInput = document.querySelector('input[type="file"]');
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('description', 'Profile photo');
const response = await fetch('https://api.example.com/upload', {
method: 'POST',
body: formData,
});
Using Python (requests)
JSON body:
import requests
response = requests.post(
'https://api.example.com/users',
json={'name': 'Alice', 'email': 'alice@example.com'}
)
print(response.json())
Using the json parameter automatically sets the Content-Type header and serializes the data.
Form-encoded body:
response = requests.post(
'https://api.example.com/users',
data={'name': 'Alice', 'email': 'alice@example.com'}
)
File upload:
with open('photo.jpg', 'rb') as f:
response = requests.post(
'https://api.example.com/upload',
files={'file': ('photo.jpg', f, 'image/jpeg')},
data={'description': 'Profile photo'}
)
Using Node.js (native fetch)
Node.js 18+ includes a built-in fetch API:
const response = await fetch('https://api.example.com/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: 'Alice', email: 'alice@example.com' }),
});
const data = await response.json();
Common Mistakes and How to Fix Them
1. Forgetting the Content-Type Header
If you send JSON without setting Content-Type: application/json, the server may treat it as plain text and fail to parse it.
# Wrong - no Content-Type
curl -X POST https://api.example.com/users \
-d '{"name": "Alice"}'
# Correct
curl -X POST https://api.example.com/users \
-H "Content-Type: application/json" \
-d '{"name": "Alice"}'
2. Setting Content-Type for FormData in JavaScript
When using FormData with fetch, do not set the Content-Type header manually. The browser needs to generate the boundary string automatically.
// Wrong - overrides the boundary
fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'multipart/form-data' },
body: formData,
});
// Correct - let the browser set it
fetch(url, {
method: 'POST',
body: formData,
});
3. Sending a Body with GET Requests
While technically not forbidden by HTTP specs, sending a body with a GET request is strongly discouraged. Many servers, proxies, and libraries will ignore or strip it.
# Bad practice
curl -X GET https://api.example.com/search \
-d '{"query": "test"}'
# Better - use query parameters
curl "https://api.example.com/search?query=test"
4. Double-Serializing JSON
A common mistake in JavaScript is stringifying an already-stringified object:
// Wrong - double serialized
const data = JSON.stringify({ name: 'Alice' });
fetch(url, {
body: JSON.stringify(data), // This wraps the string in quotes again
});
// Correct
fetch(url, {
body: JSON.stringify({ name: 'Alice' }),
});
Request Body Size Limits
Most servers and platforms enforce body size limits:
| Platform/Server | Default Limit |
|---|---|
| Nginx | 1 MB |
| Apache | 2 GB |
| Express.js (json) | 100 KB |
| Next.js API routes | 1 MB |
| AWS API Gateway | 10 MB |
| Cloudflare Workers | 100 MB |
| Vercel Serverless | 4.5 MB |
If you need to send larger payloads, consider using multipart uploads, chunked transfer encoding, or pre-signed upload URLs.
Wrapping Up
Understanding HTTP request bodies is essential for any developer working with APIs or web applications. Use JSON for most API integrations, form-encoded data for simple form submissions, and multipart for file uploads. Always set the correct Content-Type header, and be mindful of size limits in your infrastructure.
If you are building applications that involve sending media data to AI APIs, such as images for generation or videos for processing, Hypereal AI offers straightforward APIs that accept standard HTTP request formats for AI image generation, video creation, and more.
Related Articles
Start Building Today
Get 35 free credits on signup. No credit card required. Generate your first image in under 5 minutes.
