I’d like to create an API that is an intermediary to multiple back-end systems and supports both new and legacy clients. Since some of the legacy client are expecting a different response format I plan to basically “template” the response using different schemas according to what the client expects.
In my use case both responses are application/json but depending on a query parameter or a HEADER I would toggle which schema to respond to the client.
In the documentation I only see that you can have multiple responses if either:
- the media type
- the response code
But for my purpose both are application/json and both are 200.
What do you recommend to support multiple schemas?
In IRC @ddossot recommended:
in your case you probably want a different media type on the response though
since you pass the version in the Accept header
you probably have the version in a custom media type
so you probably have different media types for the different versions of the response
it would be strange to version the media type in the Accept header but not in the response Content-Type no?
because if you use the same media type for all different response schemas, how can the client know what it’s dealing with?
So that would mean that I would set multiple schemas based on different media types such as:
Is that the recommended approach?