Understanding CRUD
CRUD operations map to HTTP methods:- Create:
POST- Create a new resource - Read:
GET- Retrieve a resource - Update:
PUTorPATCH- Modify an existing resource - Delete:
DELETE- Remove a resource
Test Workflow
This example tests the QuickPizza API with a complete CRUD flow:- Setup: Create a user and retrieve an authentication token
- Create: Post a new pizza rating
- Read: Fetch the list of ratings
- Update: Modify the rating (change stars)
- Delete: Remove the rating
Core k6 API Example
Using standard k6 HTTP and check APIs:Modern API Example (httpx + k6chaijs)
Using the newerhttpx 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
- Basic Run
- Load Test
- Cloud Run
Key Concepts
Groups
Organize related requests and view grouped metrics:Checks vs Thresholds
Checks validate individual responses but don’t fail the test:Tags
Add custom tags to filter and analyze metrics:Best Practices
Use setup() for test data preparation
Use setup() for test data preparation
Avoid creating test data in every VU iteration. Use the
setup() function to create shared data once:Check responses before using data
Check responses before using data
Always validate responses before extracting data:
Clean up resources in teardown()
Clean up resources in teardown()
Remove test data after the test completes:
Related Resources
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