05 / 05

What is the role of cy.request() in Cypress?

cy.request() in Cypress is used to make HTTP requests directly, without involving the browser. It's super handy for testing APIs, seeding data, or performing actions like logging in without using the UI.​

Basic Syntax
Difficulty: 5/10
Topics: HTTP requests, API testing, Cypress commands

Scenario Questions

0-2 years experience
  1. 1

    You need to verify that a user created via the UI appears in the backend. How would you use cy.request to fetch that user and assert the email field?

  2. 2

    If a cy.request call returns a 404, what happens to the test execution, and how can you explicitly fail or continue the test?

  3. 3

    Show me how you would add a custom Authorization header to a cy.request call.

2-5 years experience
  1. 1

    Your UI test is flaky because the page sometimes takes a long time to load data. How could you replace the UI fetch with cy.request to make the test more stable, and what impact does that have on test coverage?

  2. 2

    You need to chain a request that depends on a JWT obtained from a previous request. Walk me through how you would structure the Cypress commands.

  3. 3

    During a regression a previously successful API call now returns 401. How would you use cy.request and its response object to debug the failure?

5-8 years experience
  1. 1

    The test suite contains many duplicated cy.request setups for auth tokens and base URLs. How would you refactor the code to improve maintainability and reduce repetition?

  2. 2

    You have to simulate 50 concurrent API calls to a rate‑limited endpoint. How can you orchestrate multiple cy.request calls efficiently, and what performance considerations arise?

  3. 3

    Explain how you would combine cy.request with cy.intercept to verify that the frontend correctly handles a 500 error returned by the API.

8+ years experience
  1. 1

    Your organization is shifting from UI‑heavy E2E tests to a hybrid model with extensive API testing via cy.request. What strategy would you propose for organizing test code, sharing fixtures, and ensuring coverage across multiple teams?

  2. 2

    We want to gradually replace flaky UI flows with cy.request‑based setup steps. How would you plan the migration, handle edge‑case UI interactions, and measure the impact on CI runtime?

  3. 3

    Discuss the trade‑offs between using cy.request for bulk test data seeding versus provisioning a dedicated test data service, especially regarding CI scalability and test isolation.

Follow-up Questions

  • What are the trade‑offs of using cy.request versus interacting through the UI?
  • How would you handle dynamic authentication tokens across multiple requests?
  • Can you combine cy.request with cy.intercept, and why might you do that?