In this article I will explain with an example, how to call (consume) an external REST API in ASP.Net Core MVC.
The external REST API will be called using WebClient class in ASP.Net Core MVC.
Note: For beginners in ASP.Net MVC Core, please refer my article ASP.Net MVC Core Hello World Tutorial with Sample Program example.
The JSON string returned from the API
The following JSON string is returned from the ASPSnippets Test API.
      "Name":"John Hammond",
      "Country":"United States"
      "Name":"Mudassar Khan",
      "Name":"Suzanne Mathews",
      "Name":"Robert Schidner",
You will need to import the following namespace.
using System.Net;
The Controller consists of the following Action method.
Action method for handling GET operation
Inside this Action method, first the JSON string is downloaded from an API using DownloadString method of the WebClient class.
Note: SecurityProtocol needs to be set to TLS 1.2 (3072) in order to call an API.
Finally, the JSON string is returned using the Content function.
public class HomeController : Controller
    public IActionResult Index()
        //Fetch the JSON string from URL.
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        string json = (new WebClient()).DownloadString("");
        //Return the JSON string.
        return Content(json);
Call (Consume) external API in ASP.Net Core