- Introduction
- Getting started
- Philosophy
- Comparison
- Limitations
- Debugging runbook
- FAQ
- Basics
- Concepts
- Network behavior
- Integrations
- API
- CLI
- Best practices
- Recipes
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