fs-assert-response-*

Validate HTTP responses from fetch and XHR requests

Network assertions allow you to validate HTTP responses from fetch and XHR calls. When a network request completes, Fault Sense checks the response against your assertions and resolves an associated network assertions.

Network assertions follow the form fs-assert-response-<type>="<value>" and are resolved when the HTTP response arrives.

To use network assertions, the request must include the assertion key so Fault Sense can match responses to the correct assertion. This can be done via response headers, request headers, or query parameters.

response-status

Validates that the HTTP response has a specific status code. Use this to ensure successful requests (200, 201) or expected error states (404, 500).

<form fs-assert-response-status="200">
  <!-- Form fields -->
</form>

<button fs-assert-response-status="201">
  Create Resource
</button>

response-headers

Validates that a subset of HTTP response headers match the expected values. Value is a JSON object of header name/value pairs.

<form fs-assert-response-headers='{"content-type": "application/json"}'>
  <!-- Form fields -->
</form>

<button fs-assert-response-headers='{"x-rate-limit-remaining": "99"}'>
  API Call
</button>

Associating Network Assertions

Network requests must include the assertion key to be validated. Fault Sense supports three options for associating requests with assertions (choose one). If you need to resolve a network assertion for an enpoint you do not control, add the fs-resp-for query param to the endpoints URL (Option 3)

<!-- Option 1: Response header -->
<!-- Server includes: fs-resp-for: <assertion-key> -->

<!-- Option 2: Request header -->
<!-- Client sends: fs-resp-for: <assertion-key> -->

<!-- Option 3: Query parameter -->
<form action="/api/submit?fs-resp-for=form-submission">
  <!-- Form fields -->
</form>

Complete Example

Here's a complete example showing network assertions with proper association and multiple validation criteria.

<form 
  action="/api/users"
  method="POST"
  fs-trigger="submit"
  fs-assert-response-status="201"
  fs-assert-response-headers='{"content-type": "application/json"}'
  fs-assert-timeout="5000"
>
  <input name="email" type="email" required />
  <input name="name" type="text" required />
  <button type="submit">Create User</button>
</form>

Demo Event Collector

Note: Demo Mode

The Fault Sense events shown here are real assertions that have been resolved as you played with the interactive demos.

In production, events will be sent to a backend event collection endpoint that you configure, allowing results to be aggregated across all users.

No Fault Sense events detected yet.

Interact with the examples to see events logged here.