Then the API response code should be {number}

Asserts that the HTTP status code of the most recent API response equals the given number. The expected code is any numeric status such as 200, 201, 204, 404, or 500. On mismatch the step fails with a message showing both the expected and the actual code.

A request must have been sent earlier in the scenario with one of the send-request steps; otherwise this step fails with No API response available. Because the request steps accept every status code without throwing, this assertion is the standard way to verify error responses (4xx and 5xx) as well as redirects (3xx).

Accepted phrasings

Then the API response code should be 200
Then API response code should be 200

Examples

Then the API response code should be 200
Then the API response code should be 201
Then API response code should be 404
Then API response code should be 401

In a real scenario

Feature: Content endpoint availability

  Scenario: The published articles endpoint responds correctly
    Given the API base URL is "https://api.example.org"
      And I set header "Accept" to "application/json"
     When I send a GET request to "/articles?status=published"
     Then the API response code should be 200
      And the API response should contain "articles"
     When I send a GET request to "/articles/does-not-exist"
     Then the API response code should be 404

Related steps

Back to Api Steps