Complete C# Tutorial

Handling HTTP Requests (GET, POST, PUT, DELETE) — The Heartbeat of Every API

When you start building APIs in ASP.NET Core, the first big question is:
“How do I make my app respond differently to GET, POST, PUT, and DELETE?”

Don’t worry, friend 😄.
This guide makes everything super simple by walking through .Net Core GET Example, .Net Core POST Example, .Net Core PUT Example, and .Net Core DELETE Example with clear, friendly explanations.

Real world example:

When you use any online service—like ordering food 🍕, booking a cab 🚖, or checking your bank balance 💰—your app secretly sends different types of HTTP requests behind the scenes. For example,
  1. When you view your past orders, the app uses GET;
  2. When you place a new order, it uses POST;
  3. When you edit your saved address, it uses PUT; and
  4. When you delete a card from your wallet, it uses DELETE.
In the same simple way, ASP.NET Core also works with these four core methods.

HTTP methods are just actions your app performs when someone interacts with it. In simple terms:

  • GET → bring data
  • POST → add data
  • PUT → update data
  • DELETE → remove data

By the end, you’ll feel confident and ready to build real APIs.

Let’s begin! ⭐

💡 Simple Explanation

First of all, HTTP methods help the server understand what the user wants.

Next, when the user sends a request, the controller action decides how to respond.
In other words, each method has a purpose:

👉 GET — Read
👉 POST — Create
👉 PUT — Update
👉 DELETE — Remove

For example, if someone wants all products, they send a GET request.
If they want to add a product, they send a POST request.

Because of this simple rule, writing APIs becomes easy and predictable.


🌍 Real-world Scenario

Imagine you run a small notebook shop 📒.
You store details like Name, Price, Stock.
Now customers want to:

  • See all notebooks → GET
  • Add a new notebook → POST
  • Update notebook price → PUT
  • Delete a notebook → DELETE

Your controller handles all these using four different HTTP methods — just like managing different types of customer requests at a counter.


🧩 Syntax + Explanation

ASP.NET Core uses method attributes to define HTTP method types:

				
					[HttpGet]
[HttpPost]
[HttpPut]
[HttpDelete]
				
			

These tell the framework which method should respond to which HTTP request.

🔧 Small Working Programs

Below are simple examples for each HTTP method. Each one includes output so you clearly understand what happens.


1️⃣ .Net Core GET Example

				
					[HttpGet]
[Route("notebooks")]
public IActionResult GetAll()
{
    return Ok(new string[] { "Classmate", "Spiral Book", "Soft Notebook" });
}
				
			

Output (JSON):

				
					[
  "Classmate",
  "Spiral Book",
  "Soft Notebook"
]
				
			

👉 GET retrieves data.
👉 No body required.

2️⃣ .Net Core POST Example

				
					[HttpPost]
[Route("notebooks")]
public IActionResult AddNotebook([FromBody] string name)
{
    return Ok($"Notebook '{name}' added successfully! ⭐");
}
				
			

Input (Body):

"Classmate 200 Pages"

Output:

				
					Notebook 'Classmate 200 Pages' added successfully! ⭐
				
			

👉 POST creates new entries.
👉 Always send body data.

3️⃣ .Net Core PUT Example

				
					[HttpPut]
[Route("notebooks/{id}")]
public IActionResult UpdateNotebook(int id, [FromBody] string newName)
{
    return Ok($"Notebook {id} updated to: {newName}");
}
				
			

Input (Body):

				
					"Classmate Long Book"
				
			

Output:

				
					Notebook 1 updated to: Classmate Long Book
				
			

👉 PUT updates existing data
👉 Requires both URL parameter + body

4️⃣ .Net Core DELETE Example

				
					[HttpDelete]
[Route("notebooks/{id}")]
public IActionResult DeleteNotebook(int id)
{
    return Ok($"Notebook {id} deleted successfully ❌");
}
				
			

Output:

				
					Notebook 1 deleted successfully ❌
				
			
👉 DELETE removes a record
👉 Only ID required

➕ Additional Notes

  1. Additionally, remember that GET should never modify data.
  2. Furthermore, POST and PUT usually require a body for meaningful updates.
  3. On top of that, DELETE should return meaningful confirmation messages.
  4. Also keep in mind that well-structured routes make your API easy to understand.

Testing Tip ⭐:
Use Postman, Thunder Client, or Swagger to test each method.


➡️ Next what?

You made awesome progress today! 🎉
You learned:

  • What GET, POST, PUT, DELETE do
  • How each one is written in ASP.NET Core
  • How to return JSON and text responses
  • How routes connect with different HTTP methods

👉 In the next chapter, you will learn Action Methods.
This will help you understand how controller actions really work behind the scenes.

Ready to level up? 😄

Leave a Comment

seven − 3 =

Share this Doc

Handling HTTP Requests (GET, POST, PUT, DELETE)

Or copy link