# Msw

> Mock Service Worker API mocking, request handlers, and integration testing.

- Skill: `majiayu000/msw-2` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds add majiayu000/msw-2`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/msw-2/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/msw-2

---


# MSW Skill

Expert assistance for API mocking with Mock Service Worker.

## Capabilities

- Create request handlers
- Mock REST and GraphQL APIs
- Handle network errors
- Integrate with tests
- Use in development

## Handlers

```typescript
import { http, HttpResponse } from 'msw';

export const handlers = [
  http.get('/api/users', () => {
    return HttpResponse.json([
      { id: '1', name: 'John' },
      { id: '2', name: 'Jane' },
    ]);
  }),

  http.post('/api/users', async ({ request }) => {
    const body = await request.json();
    return HttpResponse.json({ id: '3', ...body }, { status: 201 });
  }),

  http.get('/api/users/:id', ({ params }) => {
    return HttpResponse.json({ id: params.id, name: 'John' });
  }),
];
```

## Test Integration

```typescript
import { setupServer } from 'msw/node';
import { handlers } from './handlers';

const server = setupServer(...handlers);

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());
```

## Target Processes

- api-mocking
- integration-testing
- frontend-development

