Never used Django REST Framework (DRF) before, but I guess you're trying to achieve something that should be handled by your API documentation.

It crossed my mind that you're looking for describing the payload your REST API expects and that should be done dinamically by the consumer. Never saw something like that for REST as exists for SOAP, but looks like somebody already spent time on that:

https://www.ibm.com/developerworks/webservices/library/ws-restwsdl/

Never used though, you might want to experiment with it.

Besides that, some custom exception explaining the problem when wrong values were provided should help (at least the developers trying to use your API).


Em 05/07/2017 15:17, Guilherme Leal escreveu:
I'm starting a new project that uses Django (with DRF) as backend and React as frontend but I have some concerns about data consistency across what the API endpoints might expect, and what the client with React could provide.

Exemple:

Lets say I have the following model:

class Person(models.Model):
    name = models.CharField(max_length=250)
    gender = models.IntegerField(choices=MY_GENDER_CHOICES)

If one would build an API endpoint for exclusively this model, the endpoint would answer with the fields 'name' and 'gender' everytime it would be "GETed", or would accept only the fields 'name' and 'gender' when "POSTed'. Furthermore, in both cases the 'gender' field have a limited set of values it can answer/accept.

The concern I was talking about is HOW THE HELL am I going to tell the client that he only can use "this" or "that" limited set of fields or values? Even more, I want to teach the client how to discover this info, or simply put, share model specification between "client" and "server".

One thing to note: I did looked over React+Relay+GraphQL. The features are almost exactly what I was looking for, but I did find it really really really overcomplex for the size of the project I have in mind.

Anyone have anything in mind to help or sujest?
--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOs3Lp6cp8vm403D0nWd%2B09-PDZKZQOcaBcU2dvNi7LUA--%2BeA%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CAOs3Lp6cp8vm403D0nWd%2B09-PDZKZQOcaBcU2dvNi7LUA--%2BeA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5761e1ca-4887-22ae-cf27-8142f294a7ff%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to