API Request Body Builder

Construct, format, validate, and export HTTP API request payloads in seconds. Whether you are building REST JSON payloads, OAuth 2.0 form-urlencoded parameters, GraphQL mutations, or multipart uploads, this developer tool analyzes payload bytes, validates syntax, calculates hierarchy depth, and generates production-ready cURL, JavaScript fetch, and Python requests snippets. All processing executes 100% locally in your browser with zero network transmission.

Free developer tool · 100% client-side · zero data uploaded

Build, Validate & Export API Request Bodies

Construct nested REST JSON, OAuth Form URL-encoded parameters, Multipart form-data, GraphQL mutations, or XML payloads with live byte inspection, syntax diagnostics, and instant multi-language code snippets.

  • Multi-Format (JSON / Form / XML / GraphQL)
  • Real-Time Byte & Depth Counter
  • RFC 8259 Schema Diagnostics
  • cURL, Fetch & Python Generators

Request Configuration & Payload

Tip: Use user.address.city for nested keys

Payload Inspection & Code Export

VALID RFC 8259

Syntax Valid & Ready

Payload parsed successfully without errors. Ready for HTTP transmission.

Size (Bytes)
0 B
Total Keys
0
Max Depth
0
Lines
0
Payload Size Gauge (UTF-8 Bytes) 0 / 8,192 B
0 B (Lightweight) 8 KB (Microservice baseline)
RFC 8259 SYNTAX CHECK

Valid JSON payload with 0 errors. Content-Length header is 0 bytes.

# Generating cURL command...

What is an HTTP API Request Body?

An HTTP request body (also designated as the message payload or entity body) is the data sent by a client—such as a web browser, mobile application, command-line utility, or backend microservice—to a web server following the request headers. Defined formally under the Internet Engineering Task Force (IETF) specification RFC 9110 (HTTP Semantics) and RFC 9112 (HTTP/1.1), the message body carries the state representation that the client desires to create, update, or transmit.

In modern web architectures, API communication relies heavily on stateless client-server interactions. While HTTP request headers contain metadata such as authentication tokens, routing parameters, content negotiation requirements, and cache directives, the body encapsulates the functional payload: user profiles, transactional records, payment tokens, batch orders, or binary attachments. Without a well-structured, syntax-compliant body, target APIs cannot parse incoming inputs, resulting in client-side HTTP 400 Bad Request or HTTP 422 Unprocessable Entity status codes.

Supported API Payload Formats Compared

Different API endpoints and architectural paradigms require distinct serialization formats. Choosing the proper format is determined by server-side controller expectations, data hierarchy requirements, and whether binary files are involved.

Format MIME Content-Type Nesting Support Binary Uploads Typical Overhead Common Use Cases
JSON application/json Deep / Arbitrary Base64 encoded Low (compact syntax) REST APIs, Microservices, Single Page Apps
Form URL-Encoded application/x-www-form-urlencoded Flat / Limited No Very Low HTML form submissions, OAuth 2.0 token requests
Multipart Form-Data multipart/form-data Flat per boundary Yes (Native streams) Medium (Boundary delimiters) File uploads, document attachments, avatars
GraphQL application/json Deep via Variables Via multipart spec Low (Request envelope) Complex data graphs, mobile apps, unified APIs
XML application/xml Deep / Tag-based Base64 or CDATA High (Verbose markup) SOAP services, enterprise banking, legacy APIs

1. JavaScript Object Notation (JSON)

JSON (RFC 8259) is the uncontested industry standard for RESTful web services. Built upon lightweight key-value pairs, arrays, strings, numbers, booleans, and null primitives, JSON delivers high human readability and near-universal native parsing support across modern programming languages including JavaScript, Python, Go, Java, C#, and PHP. Because JSON is structured as an object hierarchy, it easily handles deep nested models such as addresses, line items, and nested customer preferences.

2. Form URL-Encoded

The application/x-www-form-urlencoded format encodes key-value pairs as percent-encoded strings separated by ampersands (e.g., grant_type=client_credentials&client_id=123), identical to the query parameter structure in URLs. It remains mandatory in high-security identity protocols like OAuth 2.0 (RFC 6749) token issuance endpoints because of its minimal attack surface and simplicity.

3. Multipart Form-Data

When an API endpoint must receive binary assets—such as PDF documents, PNG images, or video clips—alongside metadata strings, multipart/form-data is essential. Each field or file is transmitted as a separate MIME section partitioned by a unique boundary token, complete with its own Content-Disposition and Content-Type headers. This prevents costly in-memory Base64 expansion overheads.

4. GraphQL Envelopes

GraphQL requests over HTTP are transported as JSON envelopes containing two primary properties: a query string (specifying the document mutation or selection set) and an optional variables object holding dynamic values. This format enables clients to fetch exactly what they need in a single roundtrip.

5. Extensible Markup Language (XML)

XML remains prevalent in enterprise, healthcare, telecommunications, and financial systems. Governed by strict element tags and schemas (XSD), XML supports attributes, namespaces, and structured data trees, often required by SOAP protocols.

HTTP Methods and Request Body Semantics

The HTTP/1.1 specification explicitly establishes how each HTTP method interacts with request bodies. Misunderstanding method semantics is one of the most frequent causes of failed API integrations:

  • POST: Specifically intended to transmit a request body representing a subordinate resource to be created, or an action to be executed. The server assigns an identifier to the newly created entity (returning HTTP 201 Created) or processes the state change.
  • PUT: Idempotent resource replacement. The body must contain the complete, updated representation of the target resource. Sending a partial payload with PUT often inadvertently overwrites omitted attributes with null or default values.
  • PATCH: Non-idempotent or idempotent partial modification (RFC 5789). The body contains a diff or set of modifications to apply to the target resource, such as a JSON Patch array (RFC 6902) or JSON Merge Patch document (RFC 7396).
  • DELETE: While RFC 9110 allows bodies on DELETE requests, it specifies that they have no defined semantics. Many reverse proxies, cloud load balancers, and content delivery networks (CDNs) strip bodies from incoming DELETE requests entirely.
  • GET and HEAD: Must not transmit request bodies. While early specifications did not explicitly forbid bodies, RFC 9110 states that a payload within a GET request has no defined meaning and can cause server rejections, cache corruption, or request smuggling vulnerabilities.

The Critical Role of Content-Type and Content-Length Headers

When an API server receives an HTTP stream, it does not guess how to interpret the raw bytes. Two headers govern body processing:

1. Content-Type Header

The Content-Type entity header informs the receiver's deserializer which media type parser to invoke. Omitting this header or passing a mismatched value (such as sending JSON with text/plain) forces API gateways to return an HTTP 415 Unsupported Media Type response. Always include character set declarations when appropriate: application/json; charset=utf-8.

2. Content-Length vs. Transfer-Encoding

The Content-Length header denotes the exact size of the message body in octets (bytes), represented as a decimal integer. It tells the receiving socket exactly how many bytes to read before terminating the request. In UTF-8 encoding, multi-byte characters (such as emojis or non-Latin glyphs) consume between 2 and 4 bytes per character. Relying on string character count rather than byte length can lead to truncated payloads or hung socket connections. If payloads are streamed dynamically, Transfer-Encoding: chunked is utilized in place of Content-Length.

Step-by-Step: Constructing High-Performance API Payloads

  1. Determine Endpoint Requirements: Inspect the API documentation or OpenAPI/Swagger specification to verify the expected HTTP method, target URL, and content format.
  2. Define Required and Optional Fields: Distinguish between primary identity fields and optional metadata. Validate required keys before transmission.
  3. Enforce Explicit Data Types: Avoid stringifying numeric IDs, monetary amounts, or booleans unless the target API explicitly mandates string representations.
  4. Leverage Dot Notation for Hierarchies: Group related fields into nested objects (e.g., customer.shipping_address.postal_code) to maintain organized schemas.
  5. Minify for Production: Strip unnecessary indentation and whitespace prior to transmission to conserve bandwidth and reduce latency on mobile networks.
  6. Generate Test Client Commands: Create cURL, Fetch, or Python scripts to verify endpoint behavior in isolated development environments before integrating into production codebases.

Troubleshooting Common API Request Body Errors

HTTP 400 Bad Request

This status indicates that the server cannot parse the incoming payload due to syntax errors. Common causes include trailing commas in JSON objects, unescaped double quotes inside strings, unclosed brackets, or unencoded ampersands in form-urlencoded data. Use a client-side validator to pinpoint syntax line breaks.

HTTP 413 Payload Too Large

The request body exceeds the maximum buffer limit configured on the web server or API gateway. Common defaults include 1MB on NGINX (client_max_body_size) and 10MB on AWS API Gateway. Solution: Compress payloads using Gzip, paginate bulk items into smaller batches, or upload large binary assets directly to object storage (e.g., Amazon S3 pre-signed URLs) rather than routing through application servers.

HTTP 422 Unprocessable Entity

The syntax is well-formed (valid JSON or XML), but the payload fails semantic validation rules—such as passing an invalid email format, negative currency values, or missing mandatory business logic fields. Inspect the server's response body for validation error arrays.

Security Best Practices for API Payloads

  • Input Validation and Sanitization: Never trust client-supplied request bodies. All fields must be strictly typed, sanitized, and boundary-checked server-side against SQL injection, NoSQL operator injection, and cross-site scripting (XSS).
  • Prevent XML External Entity (XXE) Attacks: When processing XML payloads, disable external entity resolution and DTD processing in your XML parser to prevent arbitrary file reading and server-side request forgery (SSRF).
  • Defend Against JSON Bomb Attacks: Enforce strict maximum recursion depth and byte limits in JSON deserializers to protect servers from memory exhaustion attacks triggered by deeply nested payloads.
  • Mask Sensitive Credentials: Ensure passwords, API secrets, and payment tokens transmitted in request bodies are excluded from application logs and analytics monitors.
  • Mandate TLS 1.3 Encryption: All API requests transmitting message bodies over the public internet must be secured with HTTPS to prevent man-in-the-middle payload tampering or eavesdropping.

Frequently Asked Questions

Why does my API request fail with HTTP 400 even though my JSON appears correct?

The most common causes are trailing commas following the final item in an object or array (which standard RFC 8259 JSON forbids), unescaped quotation marks inside string values, unescaped backslashes, or control characters. In addition, ensure your HTTP client transmits the Content-Type: application/json header so the server does not parse the payload as plain text.

What is the difference between URL-encoded and Multipart form data?

application/x-www-form-urlencoded represents data as a flat string of percent-encoded key-value pairs separated by ampersands. It is lightweight and ideal for standard form fields, but cannot handle binary files. multipart/form-data breaks data into separate boundary-delimited blocks, allowing binary files and text fields to be streamed concurrently without Base64 conversion overhead.

Can a GET request have a request body according to HTTP specifications?

While the original RFC 2616 did not strictly forbid request bodies on GET requests, RFC 9110 clearly establishes that a body on a GET request has no defined semantic meaning. In practice, intermediate proxies, firewalls, and CDNs frequently drop or reject GET requests containing bodies. For querying data with complex filters, standard practice is to use URL query parameters or a POST search endpoint (such as POST /search).

Why is UTF-8 byte length different from character string length?

JavaScript and most programming languages calculate string length by UTF-16 code units. However, the HTTP Content-Length header requires the exact count of octets (bytes) transmitted. In UTF-8 encoding, standard ASCII characters consume 1 byte, while accented characters, Cyrillic glyphs, and emojis consume between 2 and 4 bytes each. A 10-character string containing emojis may actually consume 18 bytes on the wire.

How does GraphQL send request bodies over standard HTTP?

GraphQL over HTTP typically utilizes a POST request with Content-Type: application/json. The body contains a JSON object with a query string holding the GraphQL document (queries, mutations, or subscriptions) and an optional variables object holding dynamic parameters.

What is the maximum payload size supported by modern REST APIs?

HTTP specifications impose no intrinsic payload size limits. However, real-world limits are enforced by hosting environments and gateways. AWS API Gateway limits payloads to 10MB; Cloudflare limits free plans to 100MB; default NGINX installations limit bodies to 1MB unless reconfigured via client_max_body_size. High-volume APIs typically enforce thresholds between 256KB and 5MB to preserve memory efficiency.

How do I test my generated request body from the command line?

You can execute the generated cURL command directly inside your terminal, PowerShell, or command prompt. Use curl -X POST "https://api.example.com/v1/users" -H "Content-Type: application/json" -d '{"name":"Alex"}'. To inspect full request and response headers, add the verbose flag -v.