Skip to main content
Test REST API CRUD operations (Create, Read, Update, Delete) with complete request flows and authentication.

Understanding CRUD

CRUD operations map to HTTP methods:
  • Create: POST - Create a new resource
  • Read: GET - Retrieve a resource
  • Update: PUT or PATCH - Modify an existing resource
  • Delete: DELETE - Remove a resource

Test Workflow

This example tests the QuickPizza API with a complete CRUD flow:
  1. Setup: Create a user and retrieve an authentication token
  2. Create: Post a new pizza rating
  3. Read: Fetch the list of ratings
  4. Update: Modify the rating (change stars)
  5. Delete: Remove the rating

Core k6 API Example

Using standard k6 HTTP and check APIs:

Modern API Example (httpx + k6chaijs)

Using the newer httpx and k6chaijs libraries for a more expressive syntax:
The httpx session automatically handles the base URL and maintains headers across requests, making your test code cleaner.

Running the Test

Key Concepts

Groups

Organize related requests and view grouped metrics:

Checks vs Thresholds

Checks validate individual responses but don’t fail the test:
Thresholds define pass/fail criteria for the entire test:

Tags

Add custom tags to filter and analyze metrics:

Best Practices

Avoid creating test data in every VU iteration. Use the setup() function to create shared data once:
Always validate responses before extracting data:
Remove test data after the test completes:

HTTP Authentication

Learn about authentication methods

Correlation & Dynamic Data

Extract and reuse response data

Test Lifecycle

Understand setup, VU, and teardown stages

Checks & Thresholds

Define pass/fail criteria