0
0
Postmantesting~5 mins

Response size in Postman

Choose your learning style9 modes available
Introduction

Checking response size helps ensure the server sends the right amount of data. It can catch errors like missing or extra information.

When you want to confirm the API returns data within expected size limits.
When testing if large responses are handled properly by your app.
When verifying that no extra data is sent to save bandwidth.
When checking if a response is empty or too small, indicating a problem.
When monitoring response size changes after API updates.
Syntax
Postman
pm.test('Response size is correct', function () {
    pm.expect(pm.response.size().body).to.be.below(1000);
});

pm.response.size().body gives the size of the response body in bytes.

You can use comparison operators like .below(), .above(), or .equal() to check size.

Examples
This test checks if the response body size is smaller than 500 bytes.
Postman
pm.test('Response body size is less than 500 bytes', function () {
    pm.expect(pm.response.size().body).to.be.below(500);
});
This test verifies the response body size is exactly 1024 bytes.
Postman
pm.test('Response body size equals 1024 bytes', function () {
    pm.expect(pm.response.size().body).to.equal(1024);
});
This test ensures the response body size is more than 100 bytes.
Postman
pm.test('Response body size is above 100 bytes', function () {
    pm.expect(pm.response.size().body).to.be.above(100);
});
Sample Program

This test checks that the response body size is less than 2000 bytes to confirm the API is not sending too much data.

Postman
pm.test('Response size is under 2000 bytes', function () {
    pm.expect(pm.response.size().body).to.be.below(2000);
});
OutputSuccess
Important Notes

Response size includes only the body, not headers.

Use response size checks to catch unexpected large or empty responses.

Combine size checks with content checks for better test coverage.

Summary

Response size tests help verify data amount from APIs.

Use pm.response.size().body to get size in bytes.

Compare size with expected limits using assertions.