Wednesday, July 5, 2017

Re: Django + React: Shared Model Consistency


>>The easy way is provide an endpoint with valid values for that relation. 

That ideia crossed my mind more than once, but that adds at least 1 more api call (which already tends to be numerous in most cases), and while I can, will avoid that route.

>>Other than that, the client doesn't need to know about that. He can post anything and you can answer back with the errors.

The "problem in the equation" is not the relation. The problem I'm trying to avoid is exactly the "client post anything and get an error (or a list of errors) as answer". That is not productive and really meaninfull for the user experience (in a bad way).

I was trying to maybe write a django app that got the model specification, and exported some js interface to some output folder. Its basicaly the same ideia as the "types" from GraphQL.

2017-07-05 15:37 GMT-03:00 George Silva <georger.silva@gmail.com>:
Hello Guilherme,

The easy way is provide an endpoint with valid values for that relation. Other than that, the client doesn't need to know about that. He can post anything and you can answer back with the errors.

If he posts, for example, an invalid gender, you can validate that in your DRF and just spit out the errors for the client.

But there is no other way (that I can see) to let the client configure itself, without having a valid values list for that.

On Wed, Jul 5, 2017 at 3:17 PM, Guilherme Leal <lealhugui@gmail.com> wrote:
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+unsubscribe@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/CAOs3Lp6cp8vm403D0nWd%2B09-PDZKZQOcaBcU2dvNi7LUA--%2BeA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
George R. C. Silva
Sigma Geosistemas LTDA
----------------------------

--
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+unsubscribe@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/CAGyPVTvwGXOamNKtsWGyaGG-q%2BkEHXg7BTw3QBxCCeU1P6w%3D8w%40mail.gmail.com.
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+unsubscribe@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/CAOs3Lp4e70ZRZ7MreP8okDR6rgJ2xv76k1sh3BQTSM%2BR9%3D%3DXZQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment