APIRequest constructor

APIRequest({
  1. required String endpoint,
  2. HTTPMethod method = HTTPMethod.get,
  3. Map<String, String>? headers,
  4. Map<String, String>? query = const {},
  5. dynamic body,
  6. String contentType = "application/json",
  7. bool isLogResponse = false,
  8. String? baseUrl,
  9. bool isBaseResponse = true,
  10. bool isMultiLanguage = true,
})

Implementation

APIRequest({
  required this.endpoint,
  this.method = HTTPMethod.get,
  Map<String, String>? headers,
  this.query = const {},
  this.body,
  this.contentType = "application/json",
  this.isLogResponse = false,
  String? baseUrl,
  this.isBaseResponse = true,
  this.isMultiLanguage = true,
}) {
  String langCode = 'vi';
  switch (locale?.languageCode) {
    case "en":
      langCode = 'en';
      break;
    case "vi":
      langCode = 'vi';
      break;
    case "ja":
      langCode = 'jp';
      break;
  }
  final baseHeaders = {
    if (apiToken != null) 'Authorization': "Bearer $apiToken",
    if (xApplication != null) 'X-AICycle-Application': xApplication!,
    if (isMultiLanguage) "lang": langCode,
  };
  this.headers = baseHeaders;
  this.headers?.addAll(headers ?? {});
  if (baseUrl != null) {
    this.baseUrl = baseUrl;
  }
}