Skip to main content
REST API

GET User by ID

RequestValidateErrorEasy

Description

Retrieve a single user by their unique ID. Handle 404 for non-existent users.

Test Scenario

// User ids are strings (e.g. 'seed-user-2'), not integers
const response = await request.get('/api/v1/users/seed-user-2');
expect(response.status()).toBe(200);
const body = await response.json();
expect(body.data.id).toBe('seed-user-2');
Endpoint/api/v1/users/:id

Testing Tips

  • •Use path parameter for ID
  • •Check 200 for existing user
  • •Check 404 for missing user
// Playwright - GET user by ID
import { test, expect } from '@playwright/test';
test('GET /api/v1/users/:id', async ({ request }) => {
const userId = 'seed-user-2'; // ids are strings, not integers
const response = await request.get(`/api/v1/users/${userId}`);
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);
// Payload is wrapped in an envelope: { success, data: { id, name, email } }
const body = await response.json();
expect(body.data.id).toBe(userId);
expect(body.data.name).toBeDefined();
expect(body.data.email).toContain('@');
});
test('GET non-existent user returns 404', async ({ request }) => {
const response = await request.get('/api/v1/users/99999');
expect(response.status()).toBe(404);
});

Challenge ID: rest-get-user-by-id

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/users/:id

Press Enter to send