DEV Community

Cover image for Understanding HTTP Request Payloads: JSON, Form-Data, and URL-Encoded
kandz
kandz

Posted on Originally published at tools.kandz.me

Understanding HTTP Request Payloads: JSON, Form-Data, and URL-Encoded

In an HTTP request, the payload (often called the request body) is the actual data you are sending to the server. It's the content that comes after the headers in an HTTP message.

When you visit a website, your browser sends an HTTP GET request. These usually don't have a payloadβ€”you're just asking the server to send you a page.

However, when you submit a form, upload a file, or send data via a POST, PUT, or PATCH request, you attach a payload. Let's look at how that works.


How the Server Understands the Payload

The payload is just a block of bytes. To understand what those bytes mean, the server relies on the Content-Type header. This header tells the server how to parse the payload.

If you send the right payload but the wrong Content-Type, the request fails.


1. JSON (application/json)

The most common format for modern APIs. It's text-based and represents structured data.

POST /api/users HTTP/1.1
Content-Type: application/json

{
  "name": "Alice",
  "role": "admin"
}
Enter fullscreen mode Exit fullscreen mode

2. Form Data (multipart/form-data)

Used when you need to upload files. The payload is split into "parts" with boundaries.

POST /upload HTTP/1.1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="image.jpg"
Content-Type: image/jpeg

[binary file data]
------WebKitFormBoundary7MA4YWxkTrZu0gW--
Enter fullscreen mode Exit fullscreen mode

The boundary string in the header must exactly match the one in the payload. If they don't match, the server cannot parse the request.


3. URL Encoded (application/x-www-form-urlencoded)

The default format for standard HTML forms. The data is encoded as key-value pairs separated by &.

POST /login HTTP/1.1
Content-Type: application/x-www-form-urlencoded

username=alice&password=secret123
Enter fullscreen mode Exit fullscreen mode

Special characters in URL-encoded payloads must be percent-encoded (e.g., spaces become %20).


Common Gotchas When Building Payloads

  • Mismatched Content-Type: If you send JSON but tell the server it's URL-encoded, it will fail to parse.
  • Missing boundaries: For multipart/form-data, the boundary string in the header must exactly match the one in the payload.
  • Encoding issues: Special characters in URL-encoded payloads must be percent-encoded.
  • cURL conversion: Writing a cURL command by hand for a complex multipart request is error-prone.

Constructing Payloads in Code

If you're writing a script, you construct these payloads manually:

const payload = JSON.stringify({
  name: "Alice",
  role: "admin"
});

fetch('/api/users', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: payload
});
Enter fullscreen mode Exit fullscreen mode

This is fine for code. But if you just need to test an API endpoint or generate a cURL command quickly, writing the payload structure by hand is slow.


The Visual Way

If you want to construct standardized JSON, form-data, or x-www-form-urlencoded payloads without worrying about syntax, and export them directly as cURL commands, I built a free HTTP Request Payload Generator.

What it does:

  • Constructs JSON, form-data, and x-www-form-urlencoded payloads
  • Adds custom headers automatically
  • Exports ready-to-use cURL commands

Try it here

100% client-side. Nothing uploaded.


What's your preferred tool for testing HTTP requests? Do you use Postman, Insomnia, cURL, or something else? Let me know in the comments.

Top comments (0)