title: Unity Web Request Wrapper
body: <p>I'm trying to make my own JSON Web Request Wrapper on top of <a href="https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html" rel="nofollow noreferrer">UWR</a>, so it is easier to debug and change all Network requests from one script instead of debugging and changing on each scene</p>
  
  <p>But I don't know how to return a <code>string</code> from a coroutine, can anyone lend me a hand?</p>
  
  <pre><code>using System.Collections;
  using UnityEngine;
  using UnityEngine.Networking;
  
  namespace Test
  {
      public class JSONUtils : MonoBehaviour
      {
          public string GetJSON(string uri)
          {
              // How to return a string from RequestJSON?
              StartCoroutine(RequestJSON(uri));
          }
  
          private IEnumerator RequestJSON(string url)
          {
              using (UnityWebRequest www = UnityWebRequest.Get(url))
              {
                  yield return www.SendWebRequest();
  
                  if (www.isNetworkError || www.isHttpError)
                  {
                      Debug.Log(www.error);
                  }
                  else
                  {
                      yield return www.downloadHandler.text;
                  }
              }
          }
      }
  }
  </code></pre>