API to Flutter generator

While you are building mobile apps, there are some repetitive tasks. These tasks should be already automated. We have UI to be implemented. We have some architecture to set up. And usually, there is also API with which you connect your app. The last thing I mentioned is the most boring and the least changing part to be implemented in application. There are already solutions to create data models from JSON. But what if I told you, that you can generate whole API handling? Just by providing Swagger or Postman documentation, JSON? Not only models, but methods for all the endpoints as well are done for you with API to Flutter generator.

Swagger API to Flutter app implementation

The most common way of sharing API documentation during development is Swagger. Often while creating Flutter app based on API I did get it this way. Each time I implemented API it was the same monotonous job. Reading documentation and translating it to dart code. During such frustration and wasting time, I did decide to create a solution for it. Here it is, Api2Dart. Api2Dart is a tool which takes such swagger documentation as JSON and generates everything. Data models and methods for handling all endpoints included. This way, all you need to do is invoking the methods!

Interface of API2Dart - API generator for Dart and Flutter
API2Dart – API generator for Dart and Flutter

OK, so how can you use my API generation tool? Go to your swagger page (for example Pet store) and under API title copy JSON URL. Sometimes API generator tool for Flutter can’t access this URL. This occurs when CORS blocks my domain. In such case open JSON URL, copy the whole documentation, and paste to the tool. Click generate, and that’s it. You just saved yourself one day of working. Go make yourself a cup of coffee and chill.

Postman API to Flutter app implementation

The second most common API documentation that you might get to implement in Flutter app is Postman. Good for you, it got covered by API generator tool for Flutter as well! To generate API implementation for Flutter: open your Postman app, right click collection you want to get implemented and click export. The file you just got downloaded to your machine contains JSON of Postman API documentation. The JSON should be copied and pasted to API2Dart.

Postman export Collection as JSON
Postman export Collection as JSON

Other API usage

If developers did not provide documentation as Swagger or Postman collection, I have got you covered as well. It won’t be as straightforward as previous options, but it is still easier than implementing the API in Flutter app manually. To make it work with Flutter API generator, you need to add all needed endpoints to a new postman collection which will represent your API. Make sure to use variables as parameters to provide the best information to generate your Flutter app API implementation. This way you won’t need to modify the code.

Summary

OK, so that’s all! Now you can use API generator for Flutter app to boost your productivity while development. In the future, I will share more of ours internal tools that helps us build Mobile apps without a struggle. The next tool that we will make public will be probably API2APP which will generate a whole CRUD application just based on API documentation.

Also, if you are interested in boosting your UI developement make sure to check out this article.

Stonks Software House

We make mobile apps. Fast. And also blogging about app development.