The vast majority of applications consume RESTful APIs, exchanging data in JSON format, and appending some configuration in headers. The vanilla solution includes a lot of repetitive code and is a perfect target for code optimization, especially in big projects.
Flutter provides an unbelievably productive development experience, itβs an undeniable fact. Still, using tools like code generation combined with the knowledge of Dart language features and packages ecosystem may take it even further.
It's possible to significantly minimize the amount of required code while keeping all the functionality and go from βbeforeβ to βafterβ and beyond in just a few steps, leveraging code generation with retrofit
package, using API request interceptors from dio
package, and creating custom annotations thanks to Dart language features.
Learn more about this approach in my blog "Hocus pocus: painless headers customization of REST API requests in Flutter" https://link.medium.com/1PFJriUYvEb.
Top comments (0)