NativeScript Fetch to HttpClient Conversion and Gotchas

Converting fetch to HttpClient to make API calls is pretty straightforward. But sometimes it's not done correctly, especially when abusing…

NativeScript Fetch to HttpClient Conversion and Gotchas poster

Take control of your career. Build JavaScript mobile apps.

ng atlanta

Catch Dave Coffin, Nathan Walker, and Alex Ziskind at ngAtlanta in February 2020 for an advanced NativeScript with Angular workshop called  Breathe life into mobile UX with solid architecture lessons. You can register now and take your NativeScript skills up a notch.  Register here.

Converting fetch to HttpClient to make API calls is pretty straightforward. But sometimes it's not done correctly, especially when abusing the async pipe.



It may be beneficial to use HttpClient instead of the good old global fetch API that lives in a browser and NativeScript apps alike. When building Angular apps with NativeScript, using HttpClient has some added sugar like being able to use Http interceptors as well as getting an RxJS Observable as a result by default. But there are some things to watch out for when converting from using fetch to using HttpClient.



In this second part of the two-part video series, I first show you how to perform the conversion from the fetch API to using HttpClient in a NativeScript with Angular app. Then I show you some troubles you can face that may not be so obvious on the surface. And, of course, I'll show you how to eliminate those troubles.



This video builds upon what we've already done in part one: Easy Dev Backend for NativeScript apps.





You'll find more content about NativeScript in our courses area on NativeScripting.com. The new Hands-on UI course is a pretty popular starting point for those starting out learning NativeScript and how to work with UI.



Let me know if you enjoyed this short tutorial on Twitter: @digitalix or comment here. And send me your NativeScript related questions that I can answer in video form. If I select your question to make a video answer, I'll send you swag. Use the hashtag #iscriptnative.




Alex lives in Washington, DC. He's a speaker, trainer, and a Telerik Developer Expert. He's been invloved in NativeScript projects since 2015 and has created courses for Pluralsight and LinkedIn.

Did you enjoy this? Share it!

Take control of your career. Build JavaScript mobile apps.