ASP.NET Core Web API Interview

Routing, Versioning, OpenAPI/Swagger & API Documentation

ASP.NET Core Web API interview questions covering routing, API versioning, OpenAPI, Swagger and API documentation.

25 Questions Filter by level

Interview questions

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

25 Results
76
Mid-LevelIntermediate

What is routing in ASP.NET Core Web API?

Routing matches an incoming HTTP request to an API endpoint. ASP.NET Core considers route templates, HTTP methods, route values, constraints, and endpoint metadata when selecting the action that should handle a request.

77
Mid-LevelIntermediate

What are route templates in ASP.NET Core Web API?

A route template describes the URL pattern accepted by a controller or action. Templates can contain literal segments, parameters, optional values, defaults, and constraints.

78
Mid-LevelIntermediate

What are route constraints?

Route constraints restrict which URL values can match a route parameter. Common constraints include int, guid, bool, datetime, length, min, and max.

79
Mid-LevelIntermediate

What are route tokens such as [controller] and [action]?

Route tokens are placeholders replaced using controller or action metadata when routes are built. The controller token commonly removes the Controller suffix from the class name.

80
Mid-LevelIntermediate

What is a catch-all route parameter?

A catch-all route parameter captures the remaining path segments into one route value. It is useful for endpoints that intentionally accept path-like data.

81
Mid-LevelIntermediate

How should nested resources be represented in API routes?

Nested routes can express a meaningful parent-child relationship, such as a customer's orders. They are useful when the child is naturally scoped by the parent.

82
Mid-LevelIntermediate

What is URL generation in ASP.NET Core Web API?

URL generation creates a URI from route information rather than manually concatenating strings. This is useful for Location headers and links because generated URLs remain aligned with configured routing.

83
Mid-LevelIntermediate

What is LinkGenerator?

LinkGenerator is an ASP.NET Core service for generating endpoint URLs outside the convenience methods available on controllers. It can generate paths or absolute URIs using endpoint names, action information, or route values.

84
Mid-LevelIntermediate

What is API versioning?

API versioning allows an API to evolve while maintaining defined contracts for clients that still depend on older behavior. Different versions may expose different request models, response models, routes, or semantics.

85
Mid-LevelIntermediate

What are common API versioning strategies?

Common strategies include putting the version in the URL path, query string, custom header, or media type. Each approach has trade-offs involving visibility, caching, client ergonomics, and routing.

86
Mid-LevelIntermediate

When should an API introduce a new version?

A new version is appropriate when a public contract must change incompatibly and existing clients cannot safely consume the new behavior. Examples can include removing or renaming required fields, changing meanings, or restructuring resources incompatibly.

87
Mid-LevelIntermediate

What is backward compatibility in API design?

Backward compatibility means existing clients can continue operating correctly after the API is updated. Preserving field meanings, accepted inputs, status-code behavior, and documented endpoint semantics helps avoid breaking consumers.

88
Mid-LevelIntermediate

What is API deprecation?

Deprecation communicates that an API version or feature remains available temporarily but should no longer be used for new integrations and is planned for retirement.

89
Mid-LevelIntermediate

What is OpenAPI?

OpenAPI is a machine-readable specification for describing HTTP APIs. It can describe paths, operations, parameters, request bodies, response schemas, authentication requirements, and other contract metadata.

90
Mid-LevelIntermediate

What is Swagger in relation to OpenAPI?

OpenAPI is the specification, while Swagger commonly refers to a family of tools built around API descriptions, such as interactive Swagger UI. In ASP.NET Core, developers often generate an OpenAPI document and expose an interactive UI for development or documentation.

91
Mid-LevelIntermediate

How do you add Swagger/OpenAPI documentation to an ASP.NET Core Web API?

Register the required OpenAPI/Swagger services during startup and expose the generated document and UI through middleware. The exact package and APIs depend on the application's .NET version and chosen OpenAPI tooling.

92
Mid-LevelIntermediate

How can ProducesResponseType improve API documentation?

ProducesResponseType declares expected HTTP response codes and, optionally, response body types for an action. OpenAPI tooling can use this metadata to describe success and failure responses more accurately.

93
Mid-LevelIntermediate

How should authentication be documented in OpenAPI?

The OpenAPI document can define a security scheme such as HTTP bearer authentication and apply security requirements to protected operations. Interactive documentation tools can then allow a developer to supply a token when testing authorized endpoints.

94
Mid-LevelIntermediate

What are XML documentation comments used for in API documentation?

XML documentation comments can describe controllers, endpoints, parameters, return values, and DTO properties in source code. OpenAPI tooling can include the generated XML file to enrich API documentation.

95
Mid-LevelIntermediate

What are operation IDs in OpenAPI?

An operation ID is a unique identifier for an API operation within an OpenAPI document. Client generators may use operation IDs to create method names.

96
Mid-LevelIntermediate

How can API examples improve OpenAPI documentation?

Examples show clients realistic request and response payloads in addition to schemas. They can clarify formatting, optional fields, enums, error contracts, and typical values.

97
Mid-LevelIntermediate

Should Swagger UI be enabled in production?

It depends on the API's exposure model and organizational requirements. Public APIs may intentionally publish interactive documentation, while private or security-sensitive systems may disable it, restrict it to authenticated users, or expose documentation through a separate developer portal.

98
Mid-LevelIntermediate

How should breaking API changes be managed?

Identify the affected public contract, introduce a compatible path or new API version, document the change, and provide consumers enough time and guidance to migrate. Monitor usage where possible before retiring the old contract.

99
Mid-LevelIntermediate

What is contract-first versus code-first API development?

In code-first development, the application code and metadata are used to generate the API description. In contract-first development, an OpenAPI or similar contract is designed first and implementation is built to satisfy it.

100
Mid-LevelIntermediate

What are best practices for routing, versioning, and API documentation?

Use predictable resource-oriented routes, appropriate constraints, and URL generation instead of manually constructing links. Keep public routes stable and avoid unnecessary deep nesting or implementation-oriented action names.