I am trying to create a Flask application with MongoDB support that works from the same endpoints:
- The default HTML web interface
- JSON response if
Content-Type == application/json
The idea is that both a user using my browser application and a service using my API can programmatically hit http://myapp.com/users/12345 . the HTML response is served, and the second is the JSON response.
As I understand it, this corresponds to a "pure" REST, in contrast to the tradition of serving the API using a separate path, such as http://myapp.com/api/users/12345 .
There is no discussion in the Eve docs, except to say that the results are executed as JSON by default, and XML - on request.
Is there any clean way to override this behavior, for example:
- Standard response Eve JSON served if
Content-Type == application/json - Otherwise, the view applies the template to the data returned by Eve to generate an HTML response?
This seems to be an elegant means of creating an application that is both RESTful and DRY.
source share