I was looking at documentation but I am maybe missing something. If I want to receive certain fields in the request's data, how can I define them? I'd like to avoid the POST or GET method to be executed if the complete fields are not in the request's data.
Example:
I need to receive (application/json):
{ "city": "Port Orange", "state": "FL", "formatted_address": "Peach Blossom Blvd 5329", "_zip": "32128" } But if I get only
{ "city": "Port Orange", "state": "FL", "formatted_address": "Peach Blossom Blvd 5329" } I'd like return a Response with an error message 400 Bad Request. But without executing the POST method. How could I do this?
PS. I am using APIView
request.body_zipfield to your serializer. If the field is not supplied in the request, serializer will become invalid and will automatically return a 400 response.