272 views
REST API: how to create a mock service? Provide examples of tools.
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.
Also asked at RedLab
- An HTTP request—can you name its components?
- Tell me about HTTP methods. What is the difference between POST, PUT, and PATCH? What are idempotency and safety of methods?
- What is a requirements traceability matrix, what is it for, and have you used it?
- What is a bug and what is its lifecycle?
- What is the difference between cache and cookies?
Similar questions
- Is it possible to use mocks to evaluate API functionality during testing?
- What tools and programming languages were used to create Mock tests?
- What are the advantages and disadvantages of mocks when testing APIs?
- What is a mock object (stub) in testing?
- What are the main approaches and methods used in REST API development?