- Introduction
- Getting started
- Philosophy
- Comparison
- Limitations
- Debugging runbook
- FAQ
- Basics
- Concepts
- Network behavior
- Integrations
- API
- CLI
- Best practices
- Recipes
- Cookies
- Query parameters
- Response patching
- Polling
- Streaming
- Network errors
- File uploads
- Responding with binary
- Custom worker script location
- Global response delay
- GraphQL query batching
- Higher-order resolver
- Keeping mocks in sync
- Merging Service Workers
- Mock GraphQL schema
- Using CDN
- Using custom "homepage" property
- Using local HTTPS
use()
Prepend request handlers to the current worker instance.
Call signature
import { http } from 'msw'
import { worker } from './mocks/browser'
// Prepend a list of new handlers to this worker instance.
// Past this point, they extend the network behavior.
worker.use(http.get('/resource'), http.post('/resource'))
Similar to worker.start()
, you can spread a list of request handlers as
arguments to the worker.use()
method. No need to call it multiple times!
The prepended request handlers persist on the worker as long as the current runtime exists (thus, they are often referred to as “runtime request handlers”).
Related materials
- Runtime request handlers (part of a new
docs/basics/request-handler#runtime-request-handlers
section) - Network behavior overrides