C# Interview Question #186
What is a RESTful API, and how is it implemented in ASP.NET Core?
Testing, Security, APIs & Reliability Senior Advanced
Quick Interview Answer
A REST-style HTTP API models resources and uses standard HTTP methods and status codes consistently.
Detailed Explanation
A REST-style HTTP API models resources and uses standard HTTP methods and status codes consistently.
GET retrieves resources, POST commonly creates resources or starts operations, PUT replaces a resource representation, PATCH performs partial updates, and DELETE removes a resource where appropriate.
ASP.NET Core supports APIs through controllers and minimal APIs. Production APIs should use DTOs, validation, authentication and authorization where required, consistent error responses, pagination for large collections, and clear versioning or compatibility strategies.
Code Example
[ApiController]
[Route("api/products")]
public class ProductsController : ControllerBase
{
[HttpGet("{id:int}")]
public async Task<ActionResult<ProductDto>> Get(int id)
{
// Retrieve product
return Ok();
}
}