flask icon indicating copy to clipboard operation
flask copied to clipboard

Document 415 on the receiving json section

Open elafonta opened this issue 3 months ago • 1 comments

Documentation on "json" request throwing a 415 as well as 400.

The problem text is on https://flask.palletsprojects.com/en/stable/patterns/javascript/#receiving-json-in-views

Receiving JSON in Views

Use the [json](https://flask.palletsprojects.com/en/stable/api/#flask.Request.json) property of the [request](https://flask.palletsprojects.com/en/stable/api/#flask.request) object to decode the request’s body as JSON. If the body is not valid JSON, or the Content-Type header is not set to application/json, a 400 Bad Request error will be raised

I believe you want to indicate that it's a 415 instead of 400 when the Content-Type header doesn't match as it's done on https://flask.palletsprojects.com/en/stable/api/#flask.Request.json

400 is still valid for when the body isn't json (even though the content-type is json).

So maybe something like this ?

Receiving JSON in Views

Use the [json](https://flask.palletsprojects.com/en/stable/api/#flask.Request.json) property of the [request](https://flask.palletsprojects.com/en/stable/api/#flask.request) object to decode the request’s body as JSON. If the body is not valid JSON, a 400 Bad Request error will be raised.  If the Content-Type header is not set to application/json, a 415 Unsupported Media Type error will be raised

Environment:

  • Python version: N/A
  • Flask version: latest doc

This is in no way a bug, but it's for being aligned everywhere in your doc :). I'm just trying to make things better, I love the product ! thanks for the great work you've done !

elafonta avatar Oct 07 '25 15:10 elafonta

Happy to review a PR to make these two spots consistent.

davidism avatar Oct 07 '25 16:10 davidism