AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Use rxjava with retrofit enqueue12/9/2023 ![]() ![]() If you're not using OkHttp already, this might be a bit of pain point in upgrading. Retrofit 2 still uses the builder pattern for service interface instantiation, but the required argument for () (no more RestAdapter) is now an instance of OkClient. This means no more Client interface for plugging in a custom HTTP client like Volley, HttpUrlConnection, or some custom implementation that loads JSON files from disk. Retrofit 2 relies heavily on OkHttp, to the effect that OkHttp is now a required dependency for projects using Retrofit 2. I'll just give a quick overview of what I encountered in upgrading from version 1 to version 2. As such, I won't attempt to provide an exhaustive list of the changes. Jake Wharton gave a talk on it at Droidcon NYC and documentation updates are coming soon. It's a major update, well deserving of its version bump (Android 6.0 anyone?) complete with an overhauled API, a required dependency on OkHttp, and some breaking changes. Square recently released a beta version of Retrofit 2. You will use the Retrofit library to perform HTTP requests to GitHub.Menu Notes on Updating to Retrofit 2 09 September 2015 You'll compare these solutions with one that uses coroutines and see how channels can be used to share information between different coroutines. There are different ways of implementing this logic: by using blocking requests or callbacks. The list of contributors is logged after each successful request. Open the program output to ensure the data has been loaded. The UI should freeze for some time and then show the list of contributors. Make sure that the BLOCKING option is selected in the Variant dropdown menu.Ĭlick Load contributors. Provide your GitHub username and token (or password) in the corresponding fields. If the font is too small, adjust it by changing the value of setDefaultFontSize(18f) in the main() function. Open the src/contributors/main.kt file and run the main() function. Later you'll add logic to sort the users by the number of their contributions. ![]() The program loads the contributors for all of the repositories under the given organization (named “kotlin” by default). Click Generate token at the bottom of the page. Specify the name of your token, for example, coroutines-tutorial:ĭo not select any scopes. Generate a new GitHub token to use the GitHub API with your account: If you have two-factor authentication enabled, a token will be enough. To get access, provide your GitHub account name and either a password or a token. You'll be using the GitHub API in your project. You can also clone it from the command line: Before you startĭownload and install the latest version of IntelliJ IDEA.Ĭlone the project template by choosing Get from VCS on the Welcome screen or selecting File | New | Project from Version Control. You can find solutions for all of the tasks on the solutions branch of the project's repository. How to share information between different coroutines using channels.įor network requests, you'll need the Retrofit library, but the approach shown in this tutorial works similarly for any other libraries that support coroutines. How to send requests concurrently using coroutines. Why and how to use suspending functions to perform network requests. No prior knowledge of coroutines is required, but you're expected to be familiar with basic Kotlin syntax. In this tutorial, you'll learn how to use coroutines in IntelliJ IDEA to perform network requests without blocking the underlying thread or callbacks. ![]()
0 Comments
Read More
Leave a Reply. |