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'))

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”).

  • Runtime request handlers (part of a new docs/basics/request-handler#runtime-request-handlers section)
  • Network behavior overrides