Skip to main content
REST API

POST Create Order

RequestParseValidateMedium

What you will learn

  • Orders are the canonical non-idempotent POST โ€” always pair with an Idempotency-Key for retry safety
  • Test concurrent orders from the same user โ€” depends on inventory availability; race-window bugs hide here
  • Assert 201 Created + Location header pointing at the new resource โ€” clients follow Location, not body IDs

Description

Create an order with nested items. Validate complex request body structure.

Test Scenario

const response = await request.post('/api/v1/orders', {
  data: {
    userId: 1,
    items: [{ productId: 1, quantity: 2 }]
  }
});
expect(response.status()).toBe(201);
Endpoint/api/v1/orders

Testing Tips

  • โ€ขSend nested array of items
  • โ€ขValidate total calculation
  • โ€ขCheck created order has ID
// Playwright API Testing - REST
import { test, expect } from '@playwright/test';
test('REST API request', async ({ request }) => {
const response = await request.get('/api/v1/resource');
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);
const data = await response.json();
expect(data).toBeDefined();
});

Challenge ID: rest-post-create-order

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/orders

Press Enter to send