title: How to consume a API and return the content in JSON format?
body: <p>I'm struggling with the following problem:</p>
  
  <p>I've created a solution with the following projects: 1 MVC front-end and 2 test API's for testing my backend API broker.</p>
  
  <p>In my front-end I call my API broker(which is also an API) which sends requests to my 2 test API's. I'm receiving the response of this request in my API Broker in string format and I'm trying to return this into JSON to my front-end, how do I consume this api and return the response in JSON to my front-end? Look code below:</p>
  
  <p><strong>Front-end calling my API Broker:</strong></p>
  
  <pre><code>[HttpGet]
      public async Task&lt;ActionResult&gt; getCall()
      {
          string url = "http://localhost:54857/";
          string operation = "getClients";
  
          using (var client = new HttpClient())
          {
              //get logged in userID
              HttpContext context = System.Web.HttpContext.Current;
              string sessionID = context.Session["userID"].ToString();
  
              //Create request and add headers
              client.BaseAddress = new Uri(url);
              client.DefaultRequestHeaders.Accept.Clear();
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
              //Custom header
              client.DefaultRequestHeaders.Add("loggedInUser", sessionID);
  
              //Response
              HttpResponseMessage response = await client.GetAsync(operation);
              if (response.IsSuccessStatusCode)
              {
                  string jsondata = await response.Content.ReadAsStringAsync();
                  return Content(jsondata, "application/json");
              }
              return Json(1, JsonRequestBehavior.AllowGet);
          }
      }
  </code></pre>
  
  <p><strong>My API Broker consuming one of my two test API's:</strong></p>
  
  <pre><code>    [System.Web.Http.AcceptVerbs("GET")]
      [System.Web.Http.HttpGet]
      [System.Web.Http.Route("RedirectApi")]
      public void getCall()
      {
          setVariables();
  
          WebRequest request = WebRequest.Create(apiUrl);
          HttpWebResponse response = null;
          response = (HttpWebResponse)request.GetResponse();
  
          using (Stream stream = response.GetResponseStream())
          {
              StreamReader sr = new StreamReader(stream);
              var srResult = sr.ReadToEnd();
              sr.Close();
              //Return JSON object here!
  
          }
      }
  </code></pre>
  
  <p>I'm also worried that my front-end is expecting a ActionResult instead of a JSON object, I hope you I find some suggestions here.</p>
  
  <p>Thanks in advance! </p>