ASP.NET Core Web API Interview

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

ASP.NET Core Web API interview questions covering REST fundamentals, controllers, HTTP methods and status codes.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
1
JuniorBeginner

What is ASP.NET Core Web API?

ASP.NET Core Web API is a framework for building HTTP services on .NET. It is commonly used to expose application data and operations to web applications, mobile apps, desktop clients, other services, and third-party integrations.

2
JuniorBeginner

What is REST, and how is it related to Web APIs?

REST stands for Representational State Transfer. It is an architectural style for networked systems in which resources are identified by URIs and manipulated through standard HTTP semantics.

3
JuniorBeginner

What is a resource in a REST API?

A resource is a concept or entity exposed by an API, such as a product, customer, order, or invoice. A resource is normally identified by a URI and represented in a format such as JSON.

4
JuniorBeginner

What is the difference between an MVC controller and an API controller?

An MVC controller commonly returns Razor views as well as other result types and normally derives from Controller. An API controller primarily returns data and HTTP results and commonly derives from ControllerBase.

5
JuniorBeginner

What is ControllerBase in ASP.NET Core Web API?

ControllerBase is the base class commonly used for API controllers that do not need Razor view support. It provides API-focused helpers and properties such as Ok, NotFound, BadRequest, CreatedAtAction, User, Request, and ModelState.

6
JuniorBeginner

What does the [ApiController] attribute do?

The ApiController attribute enables API-specific conventions and behaviors. Important features include automatic HTTP 400 responses for invalid model state, binding-source inference, attribute-routing requirements, and improved API error behavior.

7
JuniorBeginner

Why is attribute routing commonly used for Web APIs?

Attribute routing places route templates directly on controllers and actions. It makes the HTTP contract explicit and works well for APIs because each endpoint can clearly declare its URI pattern, HTTP method, and route constraints.

8
JuniorBeginner

What is the difference between route parameters and query-string parameters?

Route parameters normally identify a particular resource or a hierarchical part of the resource path. Query-string parameters commonly represent optional filtering, searching, sorting, pagination, or other modifiers to a collection request.

9
JuniorBeginner

What are the main HTTP methods used in REST APIs?

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.

10
JuniorBeginner

What is the difference between GET and POST?

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.

11
JuniorBeginner

What is the difference between PUT and PATCH?

PUT generally represents replacement or a complete update of the target resource representation, while PATCH represents a partial modification. The exact contract must be documented because APIs sometimes use PUT with update DTOs that do not literally contain every stored field.

12
JuniorBeginner

What does idempotent mean in HTTP API design?

An operation is idempotent when repeating the same request has the same intended effect on server state as performing it once. GET, PUT, and DELETE are defined with idempotent semantics, while POST is not inherently idempotent.

13
JuniorBeginner

What does safe mean for an HTTP method?

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.

14
JuniorBeginner

What are HTTP status codes, and why are they important in Web APIs?

HTTP status codes communicate the high-level outcome of a request using a standardized protocol contract. Clients can use the status code before interpreting the response body.

15
JuniorBeginner

When should a Web API return 200 OK?

200 OK indicates that the request succeeded and the response contains a representation or result. It is commonly used for successful GET requests and for other successful operations that intentionally return a response body.

16
JuniorBeginner

When should a Web API return 201 Created?

201 Created is appropriate when a request successfully creates a new resource. The response should normally identify the URI of the newly created resource, commonly through the Location header.

17
JuniorBeginner

When should a Web API return 204 No Content?

204 No Content indicates that the request succeeded and there is intentionally no response body. It is commonly used after successful update or delete operations when the client does not need a representation returned.

18
JuniorBeginner

What is the difference between 400 Bad Request and 422 Unprocessable Content?

400 Bad Request indicates that the server cannot process the request because the request itself is invalid, such as malformed syntax or invalid API input. With ApiController, validation failures commonly produce an automatic 400 response.

19
JuniorBeginner

What is the difference between 401 Unauthorized and 403 Forbidden?

401 Unauthorized means the request lacks valid authentication credentials for the protected resource. Despite its historical name, it is primarily an authentication response.

20
JuniorBeginner

When should a Web API return 404 Not Found?

404 Not Found indicates that the requested resource or route cannot be found. For a resource endpoint, return 404 when the identifier is valid in form but no matching accessible resource exists.

21
JuniorBeginner

When should a Web API return 409 Conflict?

409 Conflict indicates that the request cannot be completed because it conflicts with the current state of the target resource or system. Examples include certain duplicate-key situations, concurrency conflicts, or state transitions that collide with existing state.

22
JuniorBeginner

What are DTOs in ASP.NET Core Web API?

DTO stands for Data Transfer Object. A DTO defines the data contract exchanged between an API and its clients, such as CreateProductRequest, UpdateProductRequest, or ProductResponse.

23
JuniorBeginner

Why should API endpoints avoid exposing EF Core entities directly?

Persistence entities are designed around database and domain concerns, while API contracts are designed for clients. Returning entities directly can expose internal fields, create serialization problems with navigation properties, encourage overposting, and tightly couple the API to the database model.

24
JuniorBeginner

What is content negotiation in ASP.NET Core Web API?

Content negotiation is the process of selecting an appropriate representation format for a response based on the endpoint capabilities and request information such as the Accept header. JSON is the normal default format for modern ASP.NET Core APIs.

25
JuniorBeginner

What are best practices for designing basic ASP.NET Core Web API endpoints?

Model endpoints around clear resources and use HTTP methods and status codes consistently. Use attribute routing, API controllers, request and response DTOs, server-side validation, asynchronous I/O, cancellation tokens, and appropriate authentication and authorization.