An HTTP server can answer a request with a status your application didn't expect. On the Linux desktop, Postman can check that status in an API test and show whether the response meets your expectation.

A status test runs after the response arrives. It checks the HTTP code the server sent. A 200 OK response can pass that assertion even when a field in the response body has the wrong value.

The Lightweight API Client runs test scripts on an open request without a Postman account. You can send the same request again to see whether a later response still meets the assertion.

Steps to write an API test in Postman:

Start in the Lightweight API Client's default layout with a new HTTP request set to GET and an empty Tests editor. Use a read-only endpoint you can call that normally returns 200. For the failure check, use a second read-only URL you control that returns a status other than 200 directly to Postman, such as 503. Avoid 3xx redirects because Postman follows them by default and may end up with a 200 response.

  1. Click the URL field beside GET.

    An empty field shows Enter URL or paste text.

  2. Enter the URL of your endpoint that returns 200.

    The example uses the following URL.

    https://api.example.test/v1/status
  3. Open the request's Tests tab.
  4. Select Status code: Code is 200 in Snippets.
    pm.test("Status code is 200", function () {
        pm.response.to.have.status(200);
    });

    The name passed to pm.test appears in Test Results. The line inside the function compares the response's status with 200.

  5. Click Send to run the request with the new assertion.
  6. Open Test Results in the response pane after the response arrives.
  7. Confirm that Status code is 200 shows PASS.
  8. Click the URL field beside GET.
  9. Select the current URL with Ctrl+A.
  10. Enter your second URL in place of the selected URL.

    This URL must return a direct non-200 response without a 3xx redirect. The example returns 503.

    https://api.example.test/v1/status/503
  11. Click Send to run the unchanged assertion against the new response.
  12. Confirm that Status code is 200 now shows FAIL in Test Results.

    The failure message gives the expected and received status codes. In the example it reports 200 and 503.

  13. Click the URL field beside GET.
  14. Select the non-200 URL with Ctrl+A.
  15. Enter your original endpoint's URL in place of the selected URL.
  16. Click Send to rerun the test on your original endpoint.
  17. Verify that Status code is 200 shows PASS again in Test Results.
Share this guide