'How can i make dynamic api service in flutter?

In my project i have to use so many http requests. I know how can i make http request for simple api call. But i want to make a service for use it in whole of my project dynamicly. Coz Models will be changed , api urls will be changed as you know. I dont want create api service for all of models again and again. So how can i make it ? Do you have any suggestions ? In normally I making api calls like :

const baseUrl = "MY_API_URL/";

class API {
  Future<SourceData> getGallery() async {
    var url = baseUrl + "Gallery?languageId=2";
    var jsonModel = null;
    var client = http.Client();
    try {
      var response = await client.get(Uri.parse(url));
      if (response.statusCode == 200) {
        var jsonMap = json.decode(response.body);
        jsonModel = SourceData.fromJson(jsonMap);
      }
      return jsonModel;
    } catch (Exc) {
      return jsonModel;
    }
  }
}

Thanks for all responses!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source