skip to Main Content

I want to make a Flutter app that uses the "Flutter" keyword to search GitHub and displays the top 50 most popular repositories.

What I tried —-
https://api.github.com/ this url has list of all available urls. Hence, from this list I took, https://api.github.com/search/repositories?q={query}{&page,per_page,sort,order} this url.
when I use this url just how it is inside of post man, I only get 29 results and if I set the page to 1 I still get 29 results and even if I set page = 2 and per_page = 25, I still get 29 results.

Please help, I need 50 results.

2

Answers


  1. You have to use the per_page parameter.

    https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28

    enter image description here

    https://api.github.com/search/repositories?q={query}&per_page=50

    Login or Signup to reply.
  2. Make sure you include the necessary dependencies in your Flutter project. You’ll need the http package for making HTTP requests. Add it to your pubspec.yaml file:

    dependencies:
     flutter:
     sdk: flutter
     http: ^0.13.3
    

    Create a new Dart file, such as github_api.dart, and import the necessary packages:

    import 'package:http/http.dart' as http;
    import 'dart:convert
    
    Define a function that will retrieve the repositories from the GitHub API:
    
    Future<List<dynamic>> fetchRepositories() async {
      final url = Uri.parse('https://api.github.com/search/repositories?q=flutter&per_page=50');
      final response = await http.get(url);
    
      if (response.statusCode == 200) {
        final Map<String, dynamic> data = json.decode(response.body);
        return data['items'];
      } else {
        throw Exception('Failed to fetch repositories');
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search