ASP.NET Core Web API – Interview Guide

1. What is ASP.NET Core Web API?

ASP.NET Core Web API is a cross-platform, high-performance framework by Microsoft used to build RESTful services for web, mobile, and microservices.


[ApiController]
[Route("api/products")]
public class ProductsController : ControllerBase
{
    [HttpGet]
    public IActionResult GetProducts()
    {
        return Ok(new[] { "Laptop", "Mobile" });
    }
}
    

2. What is REST?

REST (Representational State Transfer) is an architectural style that uses HTTP methods for CRUD operations.


[HttpGet]    // Read
[HttpPost]   // Create
[HttpPut]    // Update
[HttpDelete] // Delete
    

3. What is Routing?

Routing maps URLs to controller actions.


[Route("api/products")]
[HttpGet("{id}")]
public IActionResult GetProduct(int id)
{
    return Ok(new { Id = id, Name = "Laptop" });
}
    

4. What is ControllerBase?

ControllerBase is a base class for APIs without views. It provides helper methods like Ok(), NotFound().


public class ProductsController : ControllerBase
{
    [HttpGet]
    public IActionResult Get() => Ok("Hello API");
}
    

5. What is IActionResult?

IActionResult represents HTTP responses with status codes.


return Ok(products);              // 200 OK
return Created(uri, product);     // 201 Created
return NoContent();               // 204 No Content
return BadRequest();              // 400 Bad Request
return Unauthorized();            // 401 Unauthorized
return Forbidden();               // 403 Forbidden
return NotFound();                // 404 Not Found
return Conflict();                // 409 Conflict
return UnsupportedMediaType();    // 415 Unsupported Media Type
return InternalServerError();     // 500 Internal Server Error
return Redirect(url);             // 302 Found (Redirect)
    

6. What is Model Binding?

Automatically maps request data to parameters or models.


[HttpPost]
public IActionResult CreateProduct(Product product)
{
    return Ok(product);
}
    

7. What is Validation?

Ensures correct data before processing.


public class Product
{
    [Required]
    public string Name { get; set; }

    [Range(1, 10000)]
    public decimal Price { get; set; }
}
    

8. What is Dependency Injection?

Injects dependencies into classes for loose coupling.


builder.Services.AddScoped();

public class HomeController : Controller
{
    private readonly IMessageService _service;
    public HomeController(IMessageService service) => _service = service;
}
    

9. What is Middleware?

Middleware handles requests/responses in a pipeline.


app.Use(async (context, next) =>
{
    Console.WriteLine("Incoming request");
    await next();
    Console.WriteLine("Outgoing response");
});
    

10. What is appsettings.json?

Configuration file used for storing settings.


{
  "ConnectionStrings": {
    "Default": "Server=.;Database=TestDb;"
  }
}
    

11. What is Swagger?

Swagger provides API documentation and UI testing.


builder.Services.AddSwaggerGen();
app.UseSwagger();
app.UseSwaggerUI();
    

12. What is JSON?

JSON is a lightweight format used for data exchange.


{ "id": 1, "name": "Laptop" }
    

13. HTTP GET

Used to fetch data.


[HttpGet("{id}")]
public IActionResult GetProduct(int id) => Ok(new { Id = id, Name = "Laptop" });
    

14. HTTP POST

Used to create data.


[HttpPost]
public IActionResult CreateProduct(Product product)
{
    return CreatedAtAction(nameof(GetProduct), new { id = 1 }, product);
}
    

15. HTTP PUT & PATCH

PUT replaces full resource, PATCH updates partially.


[HttpPut("{id}")]
public IActionResult UpdateProduct(int id, Product product) => Ok(product);
    

Web API Quiz

Basic (1–15) Intermediate (16–35) Advance (36-50) Most Asking(51-100)