• Docs
  • Blog
  • Sponsor
  • Introduction
  • Getting started
  • Philosophy
  • Comparison
  • Limitations
  • Migrations
    • 1.x → 2.x
  • Debugging runbook
  • FAQ
  • Basics
    • Intercepting requests
    • Mocking responses
  • Concepts
    • Request namespace
    • Request handler
    • Response resolver
  • Network behavior
    • Describing REST API
    • Describing GraphQL API
  • Integrations
    • Browser integration
    • Node.js integration
  • API
    • setupWorker
      • start()
      • stop()
      • use()
      • resetHandlers()
      • restoreHandlers()
      • listHandlers()
    • setupServer
      • listen()
      • close()
      • use()
      • resetHandlers()
      • restoreHandlers()
      • listHandlers()
    • http
    • graphql
    • HttpResponse
    • delay
    • bypass
    • passthrough
    • RequestHandler
    • Life-cycle events
  • CLI
    • init
  • Best practices
    • Introduction
    • Structuring handlers
    • Network behavior overrides
    • Avoid request assertions
    • Custom request predicate
    • Dynamic mock scenarios
  • Recipes
    • Cookies
    • Query parameters
    • Response patching
    • Polling
    • Streaming
    • Network errors
    • Responding with binary
    • Custom worker script location
    • Higher-order resolver
    • Keeping mocks in sync
    • Mock GraphQL schema
    • Using CDN
    • Using custom "homepage" property
    • Using local HTTPS

Introduction

Our mission is to help you describe the network you want. With that in mind, we have prepared a set of best practices you can employ to improve your network descriptions.

Structuring handlers

Manage a large number of request handlers.

Network behavior overrides

Override network behaviors on runtime.

Avoid request assertions

Learn why you should not assert requests directly.

Custom request predicate

Intercept requests by custom criteria.

Dynamic mock scenarios

Apply different network scenarios on runtime.

Last updated on October 18, 2023

Edit this page on GitHub

Community

  • GitHub
  • Discord
  • Blog

© 2023 Mock Service Worker

Created with by kettanaito

Library

  • Home
  • Documentation
  • Blog

Resources

  • Getting started
  • Best practices
  • Examples

Community

  • GitHub
  • Twitter
  • YouTube