title: What's the correct usage of URLSession, create new one or reuse same one
body: <p>I am using <a href="https://developer.apple.com/documentation/foundation/urlsession" rel="noreferrer">URLSession</a> in my iOS project. (Swift 4). The following code is only for illustration purpose.</p>
  
  <pre><code>class MyTaskManager {
      ...
      func postMyData(...) {
         let defaultSession = URLSession(configuration: .default)
         dataTask = defaultSession.dataTask(with: url) { data, response, error in
           ...
         }
         dataTask.resume()
      }
  
  
      func getMyData(...) {
         let defaultSession = URLSession(configuration: .default)
         dataTask = defaultSession.dataTask(with: url) { data, response, error in
           ...
         }
         dataTask.resume()
      }
  
  }
  </code></pre>
  
  <p>I am trying to understand the best practice of using <code>URLSession</code> in the sense of whether each function call of making HTTP request should create a new <code>URLSession</code> or should I create a global one &amp; all the calls to HTTP requests should use the same <code>URLSession</code> instance?</p>
  
  <p>I have studied on internet, there is an accepted answer which says I should <a href="https://stackoverflow.com/questions/41600446/urlsession-best-practice-multiple-requests/41601005">create a new URLSession for each function/request cal</a>l , there is/are also suggestions that <a href="https://stackoverflow.com/questions/29630988/when-to-create-new-nsurlsession">I should reuse the same URLSession</a>. I get confused by those accepted but conflicting answers. Could someone clarify for me the correct answer to this question?</p>
  
  <p>My application doesn't have upload or download tasks, only pure RESTful request with JSON data format. No multiple configurations needed either. </p>