Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User API Services in Flutter

This Flutter application demonstrates how to fetch and display data from a free API using Dart. The project uses the jsonplaceholder API to fetch user data and display it on the screen.

Features

  • Fetch data from an API
  • Display data in a list view
  • Error handling for failed API requests

What is an API?

An API (Application Programming Interface) is a set of rules and definitions that allows one software application to interact with another. It defines the methods and data structures that developers use to interact with the functionalities provided by a system. In this project, we use a RESTful API provided by jsonplaceholder to fetch user data.

Getting Started

import 'dart:convert';
import 'package:http/http.dart' as http;
import 'user_model.dart';

class UserApiServices {
  String apiString = "https://jsonplaceholder.typicode.com/users";

  Future<List<UserModel>> loadData() async {
    final response = await http.get(Uri.parse(apiString));

    if (response.statusCode == 200) {
      final jsonData = jsonDecode(response.body);
      List<UserModel> finalData =
          jsonData.map<UserModel>((e) => UserModel.fromJson(e)).toList();
      return finalData;
    } else {
      throw Exception('Failed to load API');
    }
  }
}
# Pixabay Image Fetching with API in Flutter

This Flutter application demonstrates how to fetch and display images from the Pixabay API using Dart.

Features

  • Fetch images from the Pixabay API
  • Display images in a grid view
  • Error handling for failed API requests
import 'dart:convert';
import 'package:http/http.dart' as http;

class ApiService {
  Future<String?> apiCalling(String query) async {
    String api =
        'https://pixabay.com/api/?key=44453202-45ef7c677649f9bab57181230&q=$query&image_type=photo';
    Uri url = Uri.parse(api);
    http.Response response = await http.get(url);

    if (response.statusCode == 200) {
      return response.body;
    }
    return null;
  }
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages