13. Understanding APIs Web Services and its use in Flutter | Module 14 Part 1

Опубликовано: 16 Август 2022
на канале: IntelliLogics
316
8

The most common method is to show data from a database or public APIs. Even loading data from a database involves using APIs, though these can be private. So, let’s see how you can integrate APIs, fetch data from a public API, and use it in your Flutter app!

How do APIs Work?
A user application can make GET, POST, PUT, or DELETE HTTP requests to a database. In return, the database sends us data, results, or responses in the form of JSON, HTML, or XML (with the JSON format being the most widely used). We then parse the JSON into a proper model class and use it in our app.

Integrating an API into a Flutter app
There are a few steps that we can follow to easily integrate an API into our Flutter app:

Step 1: Get the API URL and endpoints.

Step 2: Add relevant packages into the app (http, dio, chopper, etc.).

Step 3: Create a constant file that stores URLs and endpoints.

Step 4: Create a model class to parse the JSON.

Step 5: Create a file that handles the API call, and write specific methods to fetch and parse data.

Step 6: Use the data in your app.