ASP.NET Core Web API Interview Question #10

What is the difference between GET and POST?

Web API & REST Fundamentals, Controllers, HTTP Methods & Status Codes Junior Beginner

Quick Interview Answer

GET is intended to retrieve a representation without requesting a state change and is considered safe. POST submits data for processing and is commonly used to create resources or execute operations that change server state.

Detailed Explanation

GET is intended to retrieve a representation without requesting a state change and is considered safe. POST submits data for processing and is commonly used to create resources or execute operations that change server state.

GET parameters are often carried in the URI, while POST commonly carries a request body. Sensitive information should not be placed in a URL merely because an endpoint uses GET.

Code Example

[HttpGet("{id:int}")]
public IActionResult Get(int id) => Ok();

[HttpPost]
public IActionResult Create(CreateProductRequest request)
    => Created("", request);