Skip to main content
REST API

POST Create User

RequestValidateParseEasy

What you will learn

  • Send idempotent POSTs with an Idempotency-Key header where the API supports it
  • Verify Location header on 201 Created and assert the resource is retrievable via GET
  • Test both happy path AND duplicate-email conflict (409) in the same suite

Description

Create a new user with JSON body. Validate required fields and response.

Test Scenario

const response = await request.post('/api/v1/users', {
  data: { name: 'John', email: 'john@test.com' }
});
expect(response.status()).toBe(201);
Endpoint/api/v1/users

Testing Tips

  • •Set Content-Type: application/json
  • •Send required fields in body
  • •Check 201 Created status
// Playwright - POST create user
import { test, expect } from '@playwright/test';
test('POST /api/v1/users', async ({ request }) => {
const newUser = {
name: 'John Doe',
email: 'john.doe@example.com',
role: 'user'
};
const response = await request.post('/api/v1/users', {
data: newUser
});
expect(response.status()).toBe(201);
const created = await response.json();
expect(created.id).toBeDefined();
expect(created.name).toBe(newUser.name);
expect(created.email).toBe(newUser.email);
});

Challenge ID: rest-post-create-user

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/users

Press Enter to send