Min Experiment No-12
Min Experiment No-12
Theory:
API stands for Application Programming Interface. It provides a set of rules and protocols for
interaction between two computers. In simple words, an API helps you connect and
communicate with a system with information so it can process and provide you with what you
want.
An API is generally made of a BaseURL and an API endpoint. Additionally, an API can
have an API key which is a private key to determine access to the API endpoint.
REST APIs
REST stands for Representational State Transfer. REST lays down some architectural
guidelines and constraints for APIs to follow.
Step 1: Find the relevant API URL and endpoint, and access it.
Step 2: Implement a model class to parse the JSON received as a response.
Step 3: Add necessary dependencies, such as http, chopper, dio, etc.
Step 4: Create a dart file to make API calls, and parse the data response.
Step 5: Use the parsed data in the application.
In this experiment, we’ve used dummyjson.com to provide us with fake JSON for
experimentation. Assuming you have a basic idea of Flutter widgets, dart, have the Flutter
SDK installed, and have already created an empty Flutter project, we’ll get started with
implementing API in our application.
If we access the API BaseURL with the endpoint in our browser, we will find a JSON array
containing some dummy product details. We will be using these data in our application in the
later stages.
Accessing data is important for any mobile web application. In thisexperiment, we’ve seen
how to use the http package to make HTTP requests for fetching data from a REST API.
We’ve built a simple application using a dummy API to see the working of the Flutter http
package in general.
Conclusion: In this experiment we have use of the http package to make HTTP requests for
fetching data from a REST API.