title: How to make GET API calls that has large JSON response in Swift 5?
body: <p>I am trying to fetch the Covid 19 data of all countries and their states from <a href="https://disease.sh/v3/covid-19/jhucsse" rel="nofollow noreferrer">disease.sh</a>.</p>
  <p>I have previously fetched json data from different APIs using this method. The response in those cases were shorter compared to this.</p>
  <p>I have posted the codes below:</p>
  <pre><code>//  Webservice.swift
  
  import Foundation
  
  class Webservice {
      
      let countriesURL: String = &quot;https://disease.sh/v3/covid-19/jhucsse&quot;
      
      func getAllCountries(completion: @escaping ([Country]?) -&gt;()) {
          
          guard let url = URL(string: countriesURL) else {
              
              completion(nil)
              return
          }
          
          let request = URLRequest(url: url)
          
          URLSession.shared.dataTask(with: request) { data, response, error in
              
              guard let data = data, error == nil else {
                  
                  print(&quot;No data in response: \(error?.localizedDescription ?? &quot;Unknown error&quot;).&quot;)
                  
                  DispatchQueue.main.async {
                      completion(nil)
                  }
                  return
              }
              
              let countries = try? JSONDecoder().decode([Country].self, from: data)
              DispatchQueue.main.async {
                  countries == nil ? completion(nil) : completion(countries)
              }
          }.resume()
          
      }
      
  }
  </code></pre>
  <p>Since, I was using MVVM design, here are my Model, ViewModel and View.</p>
  <pre><code>//  Model
  //  Country.swift
  
  import Foundation
  
  struct Country: Decodable {
      
      var country: String
      var updatedAt: String
      var stats: Stats
      var coordinates: Coordinates
      var province: String
  }
  
  struct Stats: Decodable {
      
      var confirmed: Int
      var deaths: Int
      var recovered: Int
  }
  
  struct Coordinates: Decodable {
      
      var latitude: String
      var longitude: String
  }
  </code></pre>
  <pre><code>//  ViewModel
  //  CountryListViewModel.swift
  
  import Foundation
  
  class CountryListViewModel: ObservableObject {
      
      @Published var countries = [CountryViewModel]()
      
      init() {
          fetchCountries()
      }
      
      func fetchCountries() {
          Webservice().getAllCountries() { countries in
              if let countries = countries {
                  self.countries = countries.map(CountryViewModel.init)
              }
          }
      }
      
  }
  
  
  class CountryViewModel {
      
      var country: Country
      
      init(country: Country) {
          
          self.country = country
      }
      
      let id = UUID()
      
      var name: String {
          return self.country.country
      }
      
      var updatedAt: String {
          return self.country.updatedAt
      }
      
      var stats: Stats {
          return self.country.stats
      }
      
      var coordinates: Coordinates {
          return self.country.coordinates
      }
      
      var province: String {
          return self.country.province
      }
      
  }
  </code></pre>
  <pre><code>//  View
  //  ContentView.swift
  
  
  import SwiftUI
  
  struct ContentView: View {
      
      @ObservedObject private var  countryListVM = CountryListViewModel()
      
      
      var body: some View {
          List( self.countryListVM.countries, id:\.id) { country in
              Text(country.name)
          }
      }
  }
  
  struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
          ContentView()
      }
  }
  </code></pre>
  <p>My issue is when I call the Webservice.getAllCountries() it returns nil. Could anyone look at the code and tell me what is wrong, please? Thank you!</p>
  <p>PS: I created a mock json with fewer objects (20-30) and called Webservice.getAllCountries() in this case it returned and mapped the values. It is not working with larger JSON response. <strong>Help!!</strong></p>