viewof rsNumFields = Inputs.range([2, 20], {
value: 5,
step: 1,
label: "Number of data fields:"
})
viewof rsAvgFieldSize = Inputs.range([5, 100], {
value: 25,
step: 5,
label: "Average field size (bytes):"
})
viewof rsIncludeConnectivity = Inputs.toggle({
value: true,
label: "Include connectivity metadata:"
})
viewof rsIncludeLinks = Inputs.toggle({
value: false,
label: "Include HATEOAS links:"
})
viewof rsDevicesInList = Inputs.range([1, 1000], {
value: 50,
step: 1,
label: "Devices in list response:"
})
// Base JSON overhead: braces, quotes, colons, commas
rsBaseOverhead = 2 + 20 // outer braces + device_id field
rsDataSize = rsNumFields * (rsAvgFieldSize + 15) // 15 bytes avg for key name + quotes + colon
rsConnectivitySize = rsIncludeConnectivity ? 120 : 0 // nested connectivity object
rsLinksSize = rsIncludeLinks ? 180 : 0 // HATEOAS self/collection links
rsSingleResponse = rsBaseOverhead + rsDataSize + rsConnectivitySize + rsLinksSize
rsListResponse = 50 + (rsDevicesInList * rsSingleResponse) // array wrapper + pagination
rsListResponseKB = rsListResponse / 1024
html`<div style="background: #f8f9fa; border-left: 4px solid #9B59B6; padding: 15px; margin-top: 15px; font-family: Arial, sans-serif;">
<p style="color: #2C3E50; margin-top: 0; font-weight: 700;">API Response Size Estimates</p>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px;">
<div style="background: white; padding: 12px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 12px; text-transform: uppercase; margin-bottom: 5px;">Single Device Response</div>
<div style="color: #9B59B6; font-size: 22px; font-weight: bold;">${rsSingleResponse} bytes</div>
<div style="color: #7F8C8D; font-size: 11px; margin-top: 3px;">Data: ${rsDataSize}B${rsIncludeConnectivity ? ' + Connectivity: ' + rsConnectivitySize + 'B' : ''}${rsIncludeLinks ? ' + Links: ' + rsLinksSize + 'B' : ''}</div>
</div>
<div style="background: white; padding: 12px; border-radius: 4px; border: 1px solid #e0e0e0;">
<div style="color: #7F8C8D; font-size: 12px; text-transform: uppercase; margin-bottom: 5px;">List Response (${rsDevicesInList} devices)</div>
<div style="color: ${rsListResponseKB > 100 ? '#E74C3C' : '#3498DB'}; font-size: 22px; font-weight: bold;">${rsListResponseKB < 1 ? rsListResponse + ' B' : rsListResponseKB.toFixed(1) + ' KB'}</div>
<div style="color: #7F8C8D; font-size: 11px; margin-top: 3px;">${rsListResponseKB > 100 ? 'Consider pagination!' : 'Reasonable response size'}</div>
</div>
</div>
<div style="margin-top: 12px; padding: 10px; background: #f0f7ff; border-radius: 4px; font-size: 13px; color: #2C3E50;">
<strong>Design tip:</strong> ${rsIncludeConnectivity ? 'Connectivity metadata adds ' + rsConnectivitySize + ' bytes per response but enables smart offline handling.' : 'Adding connectivity metadata (120 bytes) enables clients to handle offline devices gracefully.'}
${rsListResponseKB > 50 ? ' Use pagination (limit/offset) for list endpoints exceeding 50 KB.' : ''}
</div>
</div>`REST API Response Size Estimator
REST API Response Size Estimator
animation
rest
protocols
Try Toggle "Include connectivity metadata:" and "Include HATEOAS links:". Then press Calculate response size.
Observe After pressing Calculate response size, watch single device response and list response bytes as "Devices in list response:" changes.
Explain Describe how "Number of data fields:" changes single device response size after you press Calculate response size.
Technical boundaries. The estimate uses fixed JSON overhead, average key size, and fixed additions for connectivity metadata and HATEOAS links. List size repeats the same single response with a fixed wrapper and pagination allowance.
REST API Response Size Estimator
Calculate the size of JSON API responses with device metadata and connectivity status fields.