A Simple and Complete Guide for Web Developers
Modern web applications are often built using two main parts:
Frontend – usually written in frameworks like Angular
Backend API – often written in ASP.NET Core
These two layers need to communicate constantly. Angular sends data to ASP.NET Core through HTTP requests, and the API sends data back. This communication allows the application to log in users, load products, submit forms, or display dashboards.
In this article, you will learn in simple language:
How Angular sends data to an ASP.NET Core API
How ASP.NET Core receives and returns data
How to use GET, POST, PUT, and DELETE methods correctly
How to pass objects, arrays, query parameters, and route parameters
How to secure communication
How to test communication with tools like Postman
Common mistakes and solutions
Let’s begin.
How Angular Communicates With ASP.NET Core
Modern web applications use HTTP requests to pass data between the frontend and backend. Angular sends requests such as:
GET
POST
PUT
DELETE
ASP.NET Core receives the request, processes the data, and returns a JSON response.
Example Flow
Angular builds a request.
Sends it to API endpoint like
/api/products.ASP.NET Core receives the data.
ASP.NET Core returns a response such as JSON.
Angular displays that data on the screen.
All communication happens in JSON, which is easy to read and supported natively in both Angular and ASP.NET Core.
Setting Up ASP.NET Core API
Let us start by creating a simple ASP.NET Core API controller.
Example Model
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
Example API Controller
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
[HttpGet]
public IActionResult GetProducts()
{
var products = new List<Product>
{
new Product { Id = 1, Name = "Laptop", Price = 1200 },
new Product { Id = 2, Name = "Mouse", Price = 25 }
};
return Ok(products);
}
[HttpPost]
public IActionResult AddProduct(Product product)
{
// Save to database in real applications
return Ok(new { Message = "Product received", Received = product });
}
}
This simple controller supports:
GET to retrieve data
POST to send data
Now we connect it to Angular.
Setting Up Angular Service to Call the API
In Angular, passing data to an API is usually done in a service using the HttpClient module.
Step 1: Import HttpClientModule
In app.module.ts:
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
BrowserModule,
HttpClientModule
]
})
export class AppModule { }
Step 2: Create a Service
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class ProductService {
private apiUrl = 'https://localhost:5001/api/products';
constructor(private http: HttpClient) { }
getProducts(): Observable<any> {
return this.http.get(this.apiUrl);
}
addProduct(product: any): Observable<any> {
return this.http.post(this.apiUrl, product);
}
}
Now Angular can send and receive data.
Passing Data with GET (Fetching Data)
GET is used for retrieving data from the server.
Angular Component
this.productService.getProducts().subscribe(result => {
this.products = result;
});
ASP.NET Core
Receives GET request in:
[HttpGet]
public IActionResult GetProducts()
Output
Angular prints the list of products on the page.
Passing Data with POST (Sending Data)
POST is used when sending data (form submission, registration, adding products, etc.)
Angular Component (Sending Data)
const newProduct = {
id: 3,
name: 'Keyboard',
price: 45
};
this.productService.addProduct(newProduct).subscribe(result => {
console.log('Response:', result);
});

Join the conversation! Your thoughts help the community grow.