I am attempting to build a MongoDB-backed Flask application which serves from the same endpoints:
- A HTML web interface by default
- A JSON response if
Content-Type == application/json
The idea is that both a user consuming my application with a browser and a service consuming my API programatically can both hit http://myapp.com/users/12345 The former is served a HTML response and the latter is served a JSON response.
As I understand this is in keeping with 'pure' REST, in contrast to the tradition of serving the API from a separate path such as http://myapp.com/api/users/12345.
There is no discussion of views in the Eve docs, other than to say that results are served as JSON by default and XML if requested.
Is there any clean way to override this behaviour such that:
- The standard Eve JSON response is served if
Content-Type == application/json
- Otherwise, a view applies a template to the data returned by Eve to generate a HTML response?
This seems like it would be an elegant means of creating an application which is both RESTful and DRY.