---
title: "How Do You Consume a .NET Core API in an ASP.NET MVC Application?"  
description: "How Do You Consume a .NET Core API in an ASP.NET MVC Application?"  
author: "Ravi Misra"  
published: 2023-08-30  
updated: 2023-08-31  
canonical: https://www.mindstick.com/forum/159768/how-do-you-consume-a-dot-net-core-api-in-an-asp-dot-net-mvc-application  
category: "web api"  
tags: [".net", ".net core api"]  
reading_time: 2 minutes  

---

# How Do You Consume a .NET Core API in an ASP.NET MVC Application?

[Explain the steps involved](https://www.mindstick.com/forum/160308/explain-the-steps-involved-in-authenticating-users-using-oauth-2-0-in-a-dot-net-core-api) in consuming a .NET [Core API](https://www.mindstick.com/forum/160547/how-to-pass-multiple-parameters-in-url-dot-net-core-api) from an [ASP.NET](https://www.mindstick.com/articles/934/default-folders-available-inside-the-asp-dot-net-application-folder) [MVC application](https://www.mindstick.com/forum/12932/how-to-consume-webservices-from-asp-dot-net-mvc-application). Discuss how to use [HttpClient](https://www.mindstick.com/forum/158981/how-to-send-http-post-message-in-asp-dot-net-core-using-httpclient-post-as-json-async) or other [libraries](https://answers.mindstick.com/qa/49244/which-company-is-ahead-in-classification-of-data-for-libraries-innovations) to make [HTTP requests](https://www.mindstick.com/articles/1406/debugging-http-requests-and-http-response) to the API endpoints.

## Replies

### Reply by Aryan Kumar

To consume a .NET Core API in an [ASP.NET MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc) application, you can use the HttpClient class. The HttpClient class provides a simple and consistent way to make [HTTP](https://www.mindstick.com/blog/217/http-endpoints-in-sql-server-2005-2008) requests.

To make a GET request to an API, you can use the following code:

C#

```plaintext
using System.Net.Http;

var client = new HttpClient();
var response = await client.GetAsync("https://api.example.com/products");
```

This code will make a GET request to the `/products` endpoint of the API. The `response` variable will contain the response from the API.

Once you have received the response from the API, you can process it as needed. In this case, the response is a JSON object, so you can use the Json.NET library to parse it.

Here is an example of how to parse the response from the API:

C#

```plaintext
using System.Text.Json;

var products = await response.Content.ReadAsStringAsync();
var productList = JsonConvert.DeserializeObject<List<Product>>(products);
```

This code will parse the response from the API and store the results in a list of `Product` objects.

Here are the steps on how to consume a .NET Core API in an ASP.NET MVC application:

1. **Create an instance of the HttpClient class.**
2. **Make the HTTP request to the API.**
3. **Get the response from the API.**
4. **Parse the response from the API.**
5. **Use the data from the API.**

Here are some additional things to keep in mind when consuming a .NET Core API in an ASP.NET MVC application:

- The HttpClient class is a generic class, so you can use it to make requests to any API.
- The HttpClient class has a number of methods for making different types of HTTP requests.
- The HttpClient class has a number of properties for getting information about the response from the API.
- The Json.NET library can be used to parse JSON responses from APIs.


---

Original Source: https://www.mindstick.com/forum/159768/how-do-you-consume-a-dot-net-core-api-in-an-asp-dot-net-mvc-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
