VOOZH about

URL: https://www.geeksforgeeks.org/flutter/flutter-make-an-http-get-request/

⇱ Flutter - Make an HTTP GET Request - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Flutter - Make an HTTP GET Request

Last Updated : 23 Jul, 2025

In app development, the ability to fetch data from external sources, such as REST APIs, is a fundamental requirement. In Flutter, Whether you need to fetch data from a RESTful API, access a database, or retrieve content from a web server, Flutter provides you with the tools and packages(HTTP) to do this kind of API calls easily. Here we will explore how to interact with external data sources, retrieve JSON data, and integrate it into your Flutter application.

Required Tools

To build this app, you need the following items installed on your machine:

  • Visual Studio Code / Android Studio
  • Android Emulator / iOS Simulator / Physical Device device.
  • Flutter Installed
  • Flutter plugin for VS Code / Android Studio.

About the API

This is a joke API that gives a Random joke in each API call.

API Request method:

GET - https://api.chucknorris.io/jokes/random

JSON Data Format (Sample):

{
"categories": [],
"created_at": "2020-01-05 13:42:28.984661",
"icon_url": "https://assets.chucknorris.host/img/avatar/chuck-norris.png",
"id": "plj3-pqiRWuomVQKAy_AwQ",
"updated_at": "2020-01-05 13:42:28.984661",
"url": "https://api.chucknorris.io/jokes/plj3-pqiRWuomVQKAy_AwQ",
"value": "Chuck Norris can have his cake, eat it, then roundhouse kick you in the face with the extra power it gave him."
}

Step By Step Implementations

Step 1: Create a New Project in Android Studio

To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.

Step 2: Add the dependency to our project

In the pubspec.yaml file we have to add the below dependency for the http package which provide varrious API call methods.

dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
http: ^1.1.0

Step 3: Import the Package

First of all import material.dart file.

import 'package:flutter/material.dart';

Step 4: Create the DataModel for the JSON

Here we are going to create a DataModel class to retrieve our jokes from the API.

Step 5: Execute the main Method

Here the execution of our app starts.

Step 6: Create MyApp Class

In this class we are going to implement the MaterialApp , here we are also set the Theme of our App.

Step 7: Create APICall Class

In this class we are going to make HTTP GET request to the API endpoint and fetch the data from it.

Here is the full Code of main.dart file

Output:

Comment
Article Tags:

Explore