dobarkod / django-restless

Lightweight set of tools for building JSON-based RESTful APIs in Django
https://django-restless.readthedocs.org/en/latest/
93 stars 28 forks source link

request.content_type == 'application/json' and no payload #3

Closed itoldya closed 11 years ago

itoldya commented 12 years ago

when i send request with content_type == 'application/json' and without payload i get error 400 {"error": "invalid JSON payload: No JSON object could be decoded"}

itoldya commented 12 years ago

my english is excellent!

senko commented 12 years ago

Hey @itoldya, we're having a discussion here regarding whether it's a good thing to just set the payload to None if there isn't the payload - namely, it makes sense to require that the request be a valid JSON object if you go to the trouble of specifying the content type as JSON. So I'm thinking about reverting this change and returning 400 again for this case.

What do you think about this? Do you have a use-case where it's neccessry to specify the JSON content-type but have an empty body?

itoldya commented 12 years ago

Hello! in my project I use spinejs framework. I dont know is it right or wrong but spinejs framework to get root data send GET request with content_type = 'application/json' and no payload. How should look like request to get root data? (by root data I mean somethink like all items by category, "/api/item/category/")

senko commented 12 years ago

Ok, after a bit of digging I've found an answer here. Restless should not attempt to parse body on GET request. On all other requests, when the body is parsed, if content type is json, the body should be a valid json object.

I'll keep this bug open until someone (nudge nudge @horva :) provides a fix.

senko commented 11 years ago

Fixed in 0.0.6. Request body is not parsed for GET requests.