ASP.NET Core Web API Interview Question #9
What are the main HTTP methods used in REST APIs?
Web API & REST Fundamentals, Controllers, HTTP Methods & Status Codes Junior Beginner
Quick Interview Answer
GET retrieves a resource or collection. POST commonly creates a new resource or submits a command. PUT commonly replaces or fully updates a resource at a known URI. PATCH applies a partial update. DELETE removes a resource.
Detailed Explanation
GET retrieves a resource or collection. POST commonly creates a new resource or submits a command. PUT commonly replaces or fully updates a resource at a known URI. PATCH applies a partial update. DELETE removes a resource.
HTTP methods have defined semantics, so API design should use them consistently rather than treating every operation as an arbitrary POST.
Code Example
GET /api/products/10
POST /api/products
PUT /api/products/10
PATCH /api/products/10
DELETE /api/products/10