What is REST?
- Stateless: Each request contains all the information needed.
- Resource-based: Every piece of data is treated as a resource.
- Uses standard HTTP verbs: GET, POST, PUT, DELETE, etc.
Core RESTful HTTP Methods
1. GET — Read Data
GET /api/products/1
{ "id": 1, "name": "Laptop", "price": 1200 }
[HttpGet("{id}")] public IActionResult GetProduct(int id) { var product = _repo.GetById(id); if (product == null) return NotFound(); return Ok(product); }
2. POST — Create New Resource
POST /api/products Content-Type: application/json { "name": "Tablet", "price": 500 }
201 Created Location: /api/products/3
[HttpPost] public IActionResult CreateProduct(Product newProduct) { _repo.Add(newProduct); return CreatedAtAction(nameof(GetProduct), new { id = newProduct.Id }, newProduct); }
3. PUT — Update Existing Resource
PUT /api/products/1 Content-Type: application/json { "id": 1, "name": "Updated Laptop", "price": 1300 }
204 No Content
[HttpPut("{id}")] public IActionResult UpdateProduct(int id, Product updatedProduct) { if (id != updatedProduct.Id) return BadRequest(); var existing = _repo.GetById(id); if (existing == null) return NotFound(); _repo.Update(updatedProduct); return NoContent(); }
4. DELETE — Remove Resource
DELETE /api/products/1
204 No Content[HttpDelete("{id}")] public IActionResult DeleteProduct(int id) { var product = _repo.GetById(id); if (product == null) return NotFound(); _repo.Delete(id); return NoContent(); }
What Does Idempotent Mean in REST APIs?
"No matter how many times a client sends the same request, the result on the server remains the same."
Simple Example:
✅ DELETE /api/products/1
- First request: Deletes product with ID 1 → returns 204 No Content.
- Second request: Product already deleted → returns 404 Not Found.
💡 But the server state hasn’t changed after the second call, so DELETE is idempotent.
Understanding GET, POST, PUT, and DELETE is essential when working with RESTful APIs in ASP.NET Core or any modern backend framework. Each HTTP method serves a specific purpose and follows well-defined rules, making your API clean, maintainable, and developer-friendly.

