Thursday, September 8, 2022

Re: Checking API Results before saving

You can design a serializer for validate  api  data firstly you will  pass data in serializer and after validate serializer  you will save to model
Pseducode :
res = requests.post(url+some_endpoint, data)
serializer = demoserializer(res.data)
if serializer.is_valid():
    model.objects.create(id =  serializer.validate_data['id'])
    #do your stuff
else :
    #do something 

On Fri, Sep 2, 2022 at 5:10 AM lone...@gmail.com <lonesoac0@gmail.com> wrote:
Hello all,

    I am sending an GET request to an external API and I would like to validate the response before I save it to my model.  How do I do this?

Thank you.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0b724dc1-cb08-4168-8cc0-a5eac8a7c011n%40googlegroups.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B_kdjLg5Kxh3iC6DiU-bwrq68qTypCr4KMmh%2BA%2BFUHi6GLDww%40mail.gmail.com.

No comments:

Post a Comment