Complete Example
Complete Example
Section titled “Complete Example”This example demonstrates all major Rext HTTP features working together in a realistic API testing scenario.
The File
Section titled “The File”@configbaseUrl: https://api.example.comheaders: Content-Type: application/jsonassert: status >= 200
###@id a1b2c3@collection Auth@name LoginPOST /auth/login
{ "email": "{{email}}", "password": "{{password}}"}
@capture env.token = body.access_token@assert status == 200@assert body.token exists@assert duration < 2000
###@collection Auth@name Get Profile@pre a1b2c3GET /profileAuthorization: Bearer {{token}}
@assert status == 200@assert body.email exists@assert body.roles isArray@assert header.content-type contains jsonWhat Happens
Section titled “What Happens”1. Config is Applied
Section titled “1. Config is Applied”baseUrlis set tohttps://api.example.com- All requests get
Content-Type: application/json - Default assertion
status >= 200is added to every request
2. Login Request
Section titled “2. Login Request”- URL resolves to
https://api.example.com/auth/login {{email}}and{{password}}are resolved from the active environment- After success,
tokenis captured and saved to the environment scope - Assertions validate: status is 200, token exists, response time < 2s
3. Get Profile Request
Section titled “3. Get Profile Request”@pre a1b2c3triggers the Login request first (if not already executed){{token}}is resolved from the captured value- Assertions validate the profile response
Environment File
Section titled “Environment File”The corresponding rext.env.json:
{ "Development": { "email": "dev@example.com", "password": "dev-password" }, "Production": { "email": "admin@example.com", "password": "prod-password" }}Feature Summary
Section titled “Feature Summary”| Feature | Directives Used |
|---|---|
| Shared config | @config with baseUrl, headers, assert |
| Organization | @collection Auth, @name, @id |
| Authentication flow | @pre a1b2c3 |
| Response capture | @capture env.token = body.access_token |
| Validation | Multiple @assert directives |
| Environment variables | {{email}}, {{password}}, {{token}} |
Next Steps
Section titled “Next Steps”- Return to the Introduction
- Explore individual features in depth through the sidebar