Skip to main content

Overview

This example shows how to test a REST API using SemanticTest. We’ll test the JSONPlaceholder API, which provides fake online REST API for testing.

Complete Test

test.json

Running the Test

Expected output:

Breaking It Down

Test 1: Get User

1

Make HTTP Request

Fetch user with ID 1 from the API
2

Parse JSON Response

Convert JSON string to object
3

Validate Email Format

Check that email matches expected pattern
4

Assert Results

Verify all expectations are met

Test 2: Create Post

This test demonstrates POST requests with JSON body:
JSONPlaceholder is a fake API, so it won’t actually create the post. But it simulates the response correctly!

Test 3: Get All Posts

Shows how to validate array responses:
The status assertion verifies we got a successful response.

Variations

With Error Handling

Add retry logic for flaky endpoints:
This retries the request up to 3 times, looping while the status is not 200.

With Authentication

Add auth token to requests:

With Setup/Teardown

Clean up test data:

Next Steps

AI Chat Test

Learn how to test AI chat APIs

Error Handling

Advanced error handling patterns

HttpRequest Block

Complete HttpRequest documentation

Assertions

All available assertion operators