Test request size limits: 413 Payload Too Large and long URLs

The API docs say uploads can be 10 MB. The load balancer allows 8 MB. The framework's JSON parser allows 1 MB. A customer sends 2 MB of JSON and gets an HTML error page from the proxy, which their client can't parse.

Size limits are worth testing because each layer sets its own, and nobody owns the full picture.

Make a body of an exact size

JavaScript
// Pre-request: build a JSON body of {{targetBytes}} bytes
const target = Number(pm.variables.get('targetBytes'));
const skeleton = JSON.stringify({ name: 'size test', notes: '' });
const fill = 'x'.repeat(Math.max(0, target - skeleton.length));
pm.request.body.raw = JSON.stringify({ name: 'size test', notes: fill });

The x characters are one byte each, so the body is targetBytes long. Run it with a data file:

CSV
case,targetBytes,expected
small,1024,201
just under 1 MB,1048000,201
just over 1 MB,1049600,413
far over,5242880,413
JavaScript
const label = pm.iterationData.get('case');
pm.test(`${label}: status`, () => pm.response.to.have.status(Number(pm.iterationData.get('expected'))));
Terminal
requestarium run-collection "Notes API" --folder "Size limits" --data sizes.csv --env Staging

What a good 413 looks like

JavaScript
if (pm.response.code === 413) {
  pm.test('413 is JSON in the usual error format', () => {
    pm.expect(pm.response.headers.get('Content-Type')).to.include('json');
    pm.expect(pm.response.json()).to.have.property('error');
  });
  pm.test('413 says what the limit is', () => {
    pm.expect(pm.response.text()).to.match(/\d+\s*(MB|KB|bytes)/i);
  });
}

If the 413 is an nginx HTML page, the limit was hit at the proxy before your app saw the request. That's a finding: either raise the proxy limit above the app's limit, so the app answers, or configure the proxy's error page to match your API.

Find the real limit

If you don't know the limits, bisect: start at 1 MB and 100 MB, and halve the gap until you find the step where 201 turns into 413. Then compare that number with the docs, the gateway config and the framework config. The smallest one is the real limit; the others are wrong documentation.

Not just JSON

  • Multipart uploads often have a separate limit per file and per request.
  • Compressed bodies: a 1 MB gzip body can expand to 100 MB. If the API accepts Content-Encoding: gzip on requests, the limit should apply to the expanded size.
  • Arrays: a 900 KB body with 50,000 items may pass the byte limit and still be too much work. That's a batch limit; see batch endpoints.

Long URLs: 414

Search endpoints with many filters put everything in the query string. Servers usually cap the request line somewhere between 8 KB and 64 KB:

JavaScript
// Pre-request: a query string of about 10 KB
const ids = Array.from({ length: 1200 }, (_, i) => `id${i}`).join(',');
pm.request.url.update(`${pm.variables.get('baseUrl')}/products?ids=${ids}`);

Expect 414 URI Too Long, or, better, a documented limit on the number of ids with a 400. If long filter lists are a real use case, the API needs a POST /products/search with a body.

Large headers: 431

A cookie that grows with every feature flag eventually hits the header limit:

JavaScript
pm.request.headers.set('X-Test-Padding', 'x'.repeat(16000));

Expect 431 Request Header Fields Too Large. Mostly this is a check on your proxy; it's good to know the number before a customer finds it.