Use cy.request() to call an API endpoint directly and assert on its real response. Use cy.intercept() to observe, wait for, or stub requests that the application makes in the browser. They solve different problems: a direct cy.request() call does not pass through cy.intercept().
Write a basic Cypress API test
Cypress treats API tests as part of its end-to-end testing type. Set a baseUrl in your Cypress configuration if you want to use relative endpoint paths; otherwise, pass a full URL.
describe('GET /users', () => {
it('returns a list of users', () => {
cy.request('GET', '/users').then((response) => {
expect(response.status).to.eq(200)
expect(response.body.results).to.have.length.greaterThan(1)
})
})
})
For a focused check of a response body and duration:
cy.request('/users/1').then((response) => {
expect(response.status).to.eq(200)
expect(response.body).to.have.property('email')
expect(response.duration).to.be.lessThan(1000)
})
The duration threshold here is illustrative, not a universal service-level target. Choose one that makes sense for your API and test environment. Assert stable contract behavior or controlled test data, not incidental fixture contents. See the Cypress API testing guide for the documented approach.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Configure the API host
A configured baseUrl lets a relative request such as cy.request('/users') resolve against the application or API host. Cypress can also resolve a relative URL against the host of a page already visited; the clearest choice for a dedicated API suite is to configure its base URL explicitly. A full URL works without either.
Choose a request signature
Cypress supports cy.request(url), cy.request(url, body), cy.request(method, url), cy.request(method, url, body), and cy.request(options). Use the options form when you need headers, query parameters, a timeout, or to adjust error and redirect behavior.
Choose between cy.request(), cy.intercept(), and cy.task()
| Command | Use it for | Request or work origin | Contacts a real API? |
|---|---|---|---|
cy.request() |
Calling an endpoint directly, setting up state, or checking a real response. | Cypress’s Node process, outside the browser’s network traffic. | Yes, unless the target or environment otherwise prevents it. |
cy.intercept() |
Observing, waiting for, or controlling a request initiated by the front-end application. | The browser application. | It can pass through to the backend or return a stubbed response. |
cy.task() |
Database access, file I/O, or other work that must run in Node. | The Cypress Node process. | Not necessarily; it depends on the task you implement. |
A direct cy.request() is not browser traffic: it does not appear in the browser’s Network tab, and cy.intercept() cannot spy on or stub it. CORS and browser same-origin restrictions do not apply to this direct request. Cypress sends matching browser cookies with it and reflects response Set-Cookie values back into the browser cookie jar, which makes API-based login setup useful before UI actions.
Observe or stub an application request
Register an intercept before the UI action that should trigger the request, then wait on its alias:
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchPC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11cy.intercept('GET', '/api/users').as('getUsers')
cy.visit('/')
cy.get('[data-cy="load-users"]').click()
cy.wait('@getUsers').its('response.statusCode').should('eq', 200)
When a test needs a deterministic edge case, return a stubbed response instead of depending on backend state:
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
cy.intercept('GET', '/api/users', {
statusCode: 200,
body: { results: [] }
}).as('emptyUsers')
cy.visit('/')
cy.get('[data-cy="load-users"]').click()
cy.wait('@emptyUsers')
Use real responses when validating the integrated backend; use stubs when the purpose is to isolate front-end behavior or reach a difficult state. Cypress supports mixing those strategies across a suite.
Build useful API coverage
Seed state, exercise the UI, and verify persistence
Use direct requests for API setup, then use the interface for the behavior under test. A further request can verify that the UI action persisted the expected backend change. Cypress also documents the reverse flow: authenticate in the UI and then check an authenticated endpoint.
beforeEach(() => {
cy.request('POST', '/test/reset')
cy.request('POST', '/test/users', { email: 'reader@example.test' })
})
it('saves a profile edit', () => {
cy.visit('/profile')
cy.get('[name="displayName"]').clear().type('Reader')
cy.get('button[type="submit"]').click()
cy.request('/api/profile').then((response) => {
expect(response.body.displayName).to.eq('Reader')
})
})
The /test/reset and /test/users routes are illustrative test-support endpoints, not built-in Cypress routes. Use endpoints and test data your application actually provides.
Cover contract failures and boundaries
Direct endpoint checks can reach cases that are awkward to produce through a form. Depending on the API contract, cover invalid input, permission boundaries, rate limits, pagination edges, and expected error bodies. Keep each assertion tied to a defined response contract.
cy.request({
method: 'POST',
url: '/api/users',
body: { email: 'not-an-email' },
failOnStatusCode: false
}).then((response) => {
expect(response.status).to.eq(422)
expect(response.body).to.have.property('error')
})
Because Cypress fails on non-2xx/3xx statuses by default, set failOnStatusCode: false when an error response is the subject of the test, then assert on its status and body explicitly.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Centralize repeated authentication and request setup
If many tests need the same API prefix or authorization header, wrap that setup in a custom Cypress command instead of duplicating options. Keep environment-specific hosts and credentials in Cypress configuration or environment variables rather than committed test code. Store large payloads in fixtures, and use Cypress aliases for values needed later instead of assigning command results to ordinary JavaScript variables.
Use cy.task() for Node-only setup
Prefer an API call when the test should set up or inspect the application through its API. Use cy.task() when setup truly needs direct database access, file operations, or other Node-side work; this keeps the boundary between API behavior and test infrastructure visible.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesHandle Cypress request defaults deliberately
- Error statuses:
failOnStatusCodedefaults totrue. Turn it off only when asserting an expected non-2xx/3xx response. - Redirects: Cypress follows redirects by default. Set
followRedirect: falsewhen the test must inspect the redirect response or itsLocationbehavior. - Transient network errors: The API testing guide documents retries up to four times by default for transient network errors. It says status-code failures are not retried unless configured. Defaults are version-sensitive, so check the documentation for the Cypress release in your project.
- Timeouts:
cy.request()usesresponseTimeout, notdefaultCommandTimeout. Override a particular request with itstimeoutoption when needed. - Body serialization: Object and Boolean bodies are JSON-serialized and receive an
application/jsoncontent type. String bodies are sent as-is and do not automatically receive a content type.
Troubleshoot common API test failures
An expected error response fails the test immediately
Cause: The response status is outside the accepted 2xx/3xx range, and the default failOnStatusCode behavior is enabled. Fix: Set failOnStatusCode: false for that request and assert the expected status and response body.
cy.intercept() does not see the request
Cause: The request was made with cy.request(), which runs outside the browser proxy, or the intercept was registered after the browser action. A cached browser response may also be served without reaching the network layer. Fix: Use the response yielded by cy.request() for direct calls; for app traffic, register cy.intercept() before triggering the action. In a test environment, disabling cache headers is one documented workaround when cache behavior prevents interception.
The request goes to the wrong host
Cause: A relative path resolves against the configured baseUrl or the host of a page already visited. Fix: Set the intended API host in configuration or use a full URL, and confirm the environment-specific value is loaded by the spec.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
A request body reaches the server in an unexpected format
Cause: The test passed a string when it expected Cypress’s object-to-JSON behavior, or assumed a content type was added automatically. Fix: Pass an object for JSON payloads; for a string or another format, set the content type and serialization explicitly as required by the API.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →A request times out in CI but not locally
Cause: The API or test environment takes longer to respond than the configured response timeout. Fix: Check service availability and request timing first; then adjust the request’s timeout or project responseTimeout to a threshold justified by that environment rather than masking a slow or unavailable dependency.
Keep API tests reliable and fast
API checks avoid page rendering and simulated user interaction, so they are useful for focused endpoint contracts and efficient state setup. They do not replace UI tests: only browser tests can validate the user’s interactions and presentation. A balanced suite uses API calls to establish or inspect state and browser tests for the experience itself.
Cypress starts a browser per spec file. Group related API checks in a spec when it makes sense to amortize that startup cost; creating a separate spec for every small request can add unnecessary overhead. Avoid brittle assertions against incidental data, and use controlled test data so failures indicate a contract or behavior change rather than fixture drift.
Cypress’s current native network interception guide says that starting in Cypress 16, Chrome, Chromium, and Edge intercept test traffic on the native browser network. This concerns browser traffic handled by cy.intercept(); it does not change the separate, outside-the-browser behavior documented for cy.request(). Check the guide against the Cypress version and browser your project actually uses: Cypress network requests.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Or skip the browser setup
Cypress is the right choice when you need repeatable endpoint assertions inside an application test suite. If your separate job is to capture a page as an image or PDF, ScreenshotNeo provides a one-request screenshot API and an MCP server; it is not a replacement for Cypress API tests.
For an image capture, use the documented request shape below and replace the example target URL with the page you need. See the ScreenshotNeo API documentation for options and response details.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
- Consent banners are accepted and removed before capture, along with known newsletter popups and chat widgets; each cleanup step can be turned off.
- Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; responses identify the page verdict and billing status in headers.
- An MCP server exposes screenshot, page-info, and PDF-capture tools to AI agents and other MCP clients.
- The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month without a card.
Sources and version notes
Cypress behavior described here follows its official guides and API references. Consult the documentation for the version your project runs, especially for defaults and native interception behavior:
Quick Recap
- API testing guide
- cy.request() reference
- cy.intercept() reference
- Network requests guide
- Testing types overview
- Test performance guide
- Native network interception guide
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

