[REQ] Mock Server
Created by: ybelenko
Is your feature request related to a problem? Please describe.
Is there any server generator with mocking feature already? We briefly discussed it in #969 (closed). I'm really interested to make first one with PHP Slim framework. It's complicated topic, so we need to discuss how mock server should work.
Describe the solution you'd like
Imho, the biggest problem is to distinguish mock server from real one. Client should be fully aware to which server he's calling. It can cause problems in both ways. When you want to call mock server and accidentally call real one you can change/delete real data. And when you call mock server instead of real one by mistake, these changes doesn't really happens even if response is right.
What options do we have, I have two in my mind.
1. Detached hostname for mock server
If main hostname is my-api.tech
then mock server hostname would be mock.my-api.tech
as subdomain.
Pros
- Pretty visual and straightforward.
- Easy to call endpoints, you can even change url manually in Chrome if you need.
Cons
- Need dedicated server and full control over hosting and subdomains.
- SSL certificate for subdomains can cost extra.
- You still can call wrong url by accident. It's easy to misplace hostnames in your client sdk installation.
- You can't say from pure response whether it's mock response or not.
2. Specific HTTP Headers
Respond with mock data only when specific HTTP headers provided. Then client should send header X-MOCK-SERVER: ping
and response will contain header X-MOCK-SERVER: pong
.
Pros
- No need of dedicated server and full control over subdomains.
- Pretty hard to call mock server accidentally, almost impossible.
- With HTTP Headers we can add more mock options. Like call specific response(4xx - error response, 404 - not found etc.)
- You can say that response contains fake data when you see headers related to mock server.
- When response contains
X-MOCK-SERVER: pong
we know that server understood request correct.
Cons
- Harder to implement from client side.
- Can't call mock server with Chrome address bar.
- Need to check HTTP headers to understand that response is fake.
Additional context
It may be future standard of mock server or "Best Practices with Public API" topic, I think we need full attention before proceed. I would prefer HTTP Headers implementation and if community finds it convenient too, then we need to declare these HTTP headers and server behaviour.