In this video series we will learn how to use Retrofit, which is a type-safe HTTP client for Android and Java.
Retrofit allows easy communication with a web service by abstracting the HTTP API into a Java interface.
In part 1 we will set up Retrofit in a new Android Studio project by adding the necessary Gradle dependencies, and then already do our first GET request.
We create an interface with 1 method that we annotate with @GET and the relative URL to the API endpoint of the REST API we want to query. We then create a Retrofit instance, define the baseUrl, add GSON as the converter by passing GsonConverterFactory to the addConverterFactory method, and let Retrofit create the implementation of our API interface at compile time.
The Call object that our GET method returns encapsulates a single request + response. With enqueue we can execute this request asynchcronously on a background thread and get our result back in the onResponse callback. OnFailure will be called if something in the process of communicating with the server or processing the response went wrong. With isSuccessFull we check if our response code is between 200 and 300 and if that's the case we can retrieve our result from the response body.
GSON will parse the array of JSON objects into a List of the Java model class that we prepared beforehand.
Watch the whole playlist:
• Playlist
Retrofit + converter dependencies:
https://square.github.io/retrofit/
JSONPlaceHolder API:
https://jsonplaceholder.typicode.com/
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
In questa pagina del sito puoi guardare il video online Retrofit Tutorial Part 1 - SIMPLE GET REQUEST - Android Studio Tutorial della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Coding in Flow 18 settembre 2018, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 401,423 volte e gli è piaciuto 5.9 mille spettatori. Buona visione!