0

My api requires application/vnd.api+json to be the sole mimetype for all interaction.

If I POST to an endpoint with the header Content-Type: application/vnd.api+json, I examine the request object and request.json is None.

On the other hand, POSTing the same data with the standard Content-Type: application/json populates the request.json attr with the data I need.

What are my options to populate request.json with the data I need when using a custom mimetype? Subclassing request? Setting some parameter on the application instance?

djh
  • 401
  • 1
  • 5
  • 15
  • 1
    From my answer on the duplicate: *Flask 0.10 added the `request.get_json()` method, and you should use that method instead of the `.json` property. You can tell the method to skip the content type requirement by setting `force=True`.* – Martijn Pieters Feb 10 '16 at 22:25
  • thanks. sorry I missed the duplicate. Not-So-Hypothetical-Follow-Up: What if I am in a production environment with Flask 0.9 and upgrading third-party is not possible right now :)? Can you recommend any workaround? – djh Feb 10 '16 at 22:51
  • 1
    Use `json.loads(request.data)` in that case. – Martijn Pieters Feb 10 '16 at 23:37

0 Answers0