### Test JSONPlaceholder APIGET https://jsonplaceholder.typicode.com/users/1Accept: application/json//# status == 200//# body contains "Leanne Graham"//# body contains "@hildegard.org"
Here’s a complete example testing the HTTPBin API:
### Make a simple 200 request to HTTP BinGET http://httpbin.org/status/200Content-Type: application/json### Make a simple 404 request to HTTP BinGET http://httpbin.org/status/404Content-Type: application/json//# status == 404
This example demonstrates how HTTPSpec handles different status codes. The second request explicitly checks for a 404 response.
### Create a new resourcePOST https://api.example.com/postsContent-Type: application/jsonAuthorization: Bearer TOKEN{ "title": "Test Post", "body": "This is a test post", "userId": 1}//# status == 201//# body contains "id"//# header["content-type"] contains "application/json"### Read the created resourceGET https://api.example.com/posts/1Accept: application/jsonAuthorization: Bearer TOKEN//# status == 200//# body contains "Test Post"//# body contains "This is a test post"### Update the resourcePUT https://api.example.com/posts/1Content-Type: application/jsonAuthorization: Bearer TOKEN{ "title": "Updated Test Post", "body": "This post has been updated", "userId": 1}//# status == 200//# body contains "Updated Test Post"### Delete the resourceDELETE https://api.example.com/posts/1Authorization: Bearer TOKEN//# status == 204
Requests are executed sequentially in the order they appear. This is perfect for testing workflows, but be aware that later tests may depend on earlier ones succeeding.
HTTPSpec makes it easy to test various HTTP status codes:
2xx Success
4xx Client Errors
5xx Server Errors
### Test 200 OKGET http://httpbin.org/status/200//# status == 200### Test 201 CreatedGET http://httpbin.org/status/201//# status == 201### Test 204 No ContentGET http://httpbin.org/status/204//# status == 204
### Test 400 Bad RequestGET http://httpbin.org/status/400//# status == 400### Test 401 UnauthorizedGET http://httpbin.org/status/401//# status == 401### Test 404 Not FoundGET http://httpbin.org/status/404//# status == 404
### Test 500 Internal Server ErrorGET http://httpbin.org/status/500//# status == 500### Test 503 Service UnavailableGET http://httpbin.org/status/503//# status == 503
### Test with Bearer tokenGET https://api.example.com/protectedAuthorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...//# status == 200//# body contains "authenticated"
Always test both successful responses and expected failures:
### Valid request should succeedGET https://api.example.com/users/1//# status == 200### Invalid ID should failGET https://api.example.com/users/999999//# status == 404
Validate response structure
Use contains to check for expected fields in JSON responses:
//# body contains "id"//# body contains "email"//# body contains "created_at"