0% found this document useful (0 votes)
7 views

Min Experiment No-12

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Min Experiment No-12

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

PARSHVANATH CHARITABLE TRUST'S

A. P. SHAH INSTITUTE OF TECHNOLOGY


(All Branches NBA Accredited)

Department of Information Technology


Academic Year: 2023-24 Name of Student:
Semester: VI Student ID:
Class / Branch: TE- IT Roll No.
Subject: MAD & PWA Lab Date of Submission:
Name of Instructor: Yaminee Patil
Experiment No.:12
Aim: To integrate API in flutter to retrieve data from a public API
Prerequisites: HTML, JavaScript, JSON.
Software: VS code, Browser,JSON File.
Problem Statement: Make use of 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.

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.

Steps to Fetch Data from REST APIs in Flutter App


We will be following some of these steps in order to fetch data from APIs into our Flutter
application:

 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.

Department of Information Technology | AP SIT


PARSHVANATH CHARITABLE TRUST'S

A. P. SHAH INSTITUTE OF TECHNOLOGY


(All Branches NBA Accredited)

We can access our API by visiting dummyjson.com/products.

Here the BaseURL is dummyjson.com and the API endpoint is /products.

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.

Department of Information Technology | AP SIT

You might also like