Skip to content
Middle272 views

REST API: how to create a mock service? Provide examples of tools.

Practice

Asked at

AI answer

A mock service simulates an API so you can develop and test a client or integrations without a real server. Typically, you define routes, methods, expected requests and responses, and, when needed, delays, errors, and state scenarios.

Examples of tools:

  • WireMock — HTTP server stubs and mocks, useful for integration tests.
  • Mockoon — a convenient GUI for creating local REST mocks.
  • Postman Mock Server — mocks based on a collection of sample requests and responses.
  • Prism — generates and validates mocks from an OpenAPI specification.
  • MSW (Mock Service Worker) — intercepts requests in a browser or Node.js and is often used in frontend tests.

For example, you can configure GET /users/42 to return 200 with a JSON user, and an unknown ID to return 404. It’s important to keep the mock aligned with the API contract and verify it against OpenAPI or the real server; otherwise, tests may pass against outdated behavior.