Performance: Testing POST with request body
MEDIUM IMPACT
This concept affects server response time and client perceived latency when handling POST requests with body data.
const request = require('supertest'); const app = require('./app'); describe('POST /api/data', () => { it('should respond with 200', async () => { const res = await request(app) .post('/api/data') .send({ name: 'John', age: 30 }) .set('Content-Type', 'application/json'); expect(res.statusCode).toBe(200); }); });
const request = require('supertest'); const app = require('./app'); describe('POST /api/data', () => { it('should respond with 200', async () => { const res = await request(app) .post('/api/data') .send('name=John&age=30') .set('Content-Type', 'application/x-www-form-urlencoded'); expect(res.statusCode).toBe(200); }); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Raw URL-encoded string body | N/A | N/A | N/A | [X] Bad |
| JSON object body with correct Content-Type | N/A | N/A | N/A | [OK] Good |