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

Publicado el: 28 octubre 2018
en el canal de: 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


En esta página del sitio puede ver el video en línea Retrofit Tutorial Part 4 - PUT, PATCH & DELETE REQUEST - Android Studio Tutorial de Duración hora minuto segunda en buena calidad , que subió el usuario Coding in Flow 28 octubre 2018, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 57,954 veces y le gustó 929 a los espectadores. Disfruta viendo!