How to PUT request using UrlRequest() method?

45 views
Skip to first unread message

Himanshu Pharawal

unread,
Aug 6, 2019, 8:53:43 AM8/6/19
to Kivy users support
I am able to send get and post request.

Andrei Sima

unread,
Aug 9, 2019, 3:07:10 AM8/9/19
to Kivy users support
Depending on your server configuration PUT might be PATCH

Create -> POTS
Retrieve -> GET
Update -> PUT or PATCH. In Django Rest PUT is updating the entire model object, PATCH is updating only the field from the model object.
Delete -> DELETE (as a standard method but you can do a fake DELETE and archive the deleted data :) )

Also depending on the server custom method can be implemented.


____________________
Andrei Sima
0723.223.883


On Tue, Aug 6, 2019 at 3:53 PM Himanshu Pharawal <himanshup...@gmail.com> wrote:
I am able to send get and post request.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/5b7b7b4b-d3b7-4ede-b0a4-33ab578a2b40%40googlegroups.com.

Andrei Sima

unread,
Aug 9, 2019, 3:09:02 AM8/9/19
to Kivy users support
Also make sure that PUT and PATCH are implemented methods and that they are available to you. I sometimes do not want to expose Update methods to all users.
____________________
Andrei Sima
0723.223.883

Andrei Sima

unread,
Aug 9, 2019, 5:58:29 AM8/9/19
to Kivy users support
And here is my example on how i use it on Kivy

from kivy.network.urlrequest import UrlRequest

def patch_data (self, value, uuid):

     host = '<your api server>'
     endpoint = f'/switches/switches/{uuid}/'
     url = host+endpoint

     headers = { 'content-type': "application/json" }
     body = {'value': value}  # here if you want to use POST you need to send the entire object that you want to updata
     body = json.dumps(body)
     method = 'PATCH'

     req = UrlRequest(url = url,
         req_headers = headers,
         req_body = body,
         method = method,
         on_success = self.req_response,
         on_failure = self.req_failure)
        # here you can implement more methods based on documentation

def req_response (self, req, result):
     print(result)

def req_failure (self, req, result):
     print (f'Failure is an option nowadays: {result}')


Hope it helps

____________________
Andrei Sima
0723.223.883

Reply all
Reply to author
Forward
0 new messages