Retrofit Tutorial Part 4 - PUT, PATCH & DELETE REQUEST - Android Studio Tutorial

Veröffentlicht am: 28 Oktober 2018
auf dem Kanal: Coding in Flow
57,954
929

In part 4 of the Retrofit tutorial, we will learn how to make PUT, PATCH and DELETE requests on a REST API.
PUT and PATCH are the HTTP methods that we use to update data on a server.
While PATCH only changes the specific fields we send over, PUT completely replaces the existing entity with the one in the request body (or alternatively creates it).
A DELETE request deletes an existing resource.
PUT, PATCH and DELETE are usually applied on a single item rather than a collection as a whole.
As usual, we declare these methods in our API Java interface and annotate them with their corresponding HTTP call: @PUT, @PATCH or @DELETE. With @Path placeholders we dynamically specify the URL endpoint on which we want to modify a resource. PUT and PATCH both send a @Body annotated request body, which the GSON converter serializes into the JSON format. By calling serializeNulls on a GsonBuilder and passing the Gson instance to the GsonConverterFactory's create method in addConverterFactory, we can tell GSON to not drop null values in the serialzation process. Alternatively we can send single fields @FormUrlEncoded.
DELETE returns a Call of type Void, with which we specify that we don't want to read the response body. A successful delete operation is indicated by a 200 (OK) response code.
As usual, we run our network requests on a background thread, by calling enqueue instead of execute, and handle the results in the onResponse and onFailure callbacks.

Watch the whole playlist:
   • Playlist  

Example code for this part:
https://gist.github.com/codinginflow/...

____________________
💻 Find the BEST programming tutorials on TutHub:
https://tuthub.io

⭐ Get my MVVM Caching Course now:
https://codinginflow.com/caching

❗ Subscribe to the channel:
   / codinginflo.  .

📨 Subscribe to the Coding in Flow newsletter:
https://codinginflow.com/newsletter

❓ Join our free developer community:
  / discord  

📣 Follow Coding in Flow on other sites:
Facebook:   / codinginflow  
Instagram:   / codinginflow  
TikTok:   / codinginflow  
Twitter:   / codinginflow  
Github: https://github.com/codinginflow

💰 Business requests, sponsoring, etc.: info@codinginflow.com


Auf dieser Seite können Sie das Online-Video Retrofit Tutorial Part 4 - PUT, PATCH & DELETE REQUEST - Android Studio Tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Coding in Flow 28 Oktober 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 57,954 Mal angesehen und es wurde von 929 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!