ASP.NET Core Web API Interview Question #13
What does safe mean for an HTTP method?
Web API & REST Fundamentals, Controllers, HTTP Methods & Status Codes Junior Beginner
Quick Interview Answer
A safe HTTP method is intended only for retrieval and should not request a state change in application data. GET, HEAD, and OPTIONS are examples of safe methods.
Detailed Explanation
A safe HTTP method is intended only for retrieval and should not request a state change in application data. GET, HEAD, and OPTIONS are examples of safe methods.
A GET request may still produce incidental effects such as logging or metrics, but it should not perform business actions such as deleting a record, charging a payment, or approving an order.
Code Example
// Correct: retrieval
[HttpGet("{id:int}")]
public IActionResult Get(int id) => Ok();
// Do not design:
// GET /api/orders/10/delete