Advertisement

Endpoint Metadata, Route Constraints & Templates interview questions and answers

15 Endpoint Metadata, Route Constraints & Templates interview questions for ASP.NET Core roles, each with a model answer, examples and likely follow-ups.

15 questions
Advertisement

15 questions

Q11 Advanced Save

How do you generate a URL for a named route or endpoint programmatically, rather than hardcoding URL strings throughout the application (like in a Location header for a 201 Created response)?

Named endpoints (via .WithName("GetProduct") in minimal APIs or route names in controller attributes) can be referenced by LinkGenerator.GetPathByName() or Results.CreatedAtRoute()/CreatedAtAction() to generate the correct URL dynamically, ensuring links stay correct even if the underlying route template changes later, rather than hardcoding a URL string that could silently become stale.
app.MapGet("/products/{id}", GetById).WithName("GetProduct");

app.MapPost("/products", (ProductDto dto) => {
    var product = _service.Create(dto);
    return Results.CreatedAtRoute("GetProduct", new { id = product.Id }, product);
    // generates the correct Location header URL by referencing the named route
});
Real-world example
A POST endpoint creating a new product returns a 201 Created response with a correctly-generated Location header pointing to the new resource, using CreatedAtRoute referencing the named GetProduct route rather than manually string-concatenating a URL that could drift out of sync if the route template ever changes.
Likely follow-ups
  • What is REST's requirement around returning a Location header for 201 responses, and why does this matter?
  • How does LinkGenerator work outside the context of an active HTTP request, like in a background service sending an email with a link?
RESTful Web APIs & Controllers Model Binding & Validation
Q12 Intermediate Save

How do route parameter transformers let you customize the casing convention of generated URLs, such as converting PascalCase action names to kebab-case URLs?

IOutboundParameterTransformer implementations (registered via RouteOptions) can transform route values during URL generation, most commonly used to automatically convert PascalCase controller/action names into kebab-case URL segments (a common REST API convention), avoiding the need to manually specify a custom [Route] template on every single action just for casing.
public class KebabCaseParameterTransformer : IOutboundParameterTransformer {
    public string? TransformOutbound(object? value) =>
        value is null ? null : Regex.Replace(value.ToString()!, "([a-z])([A-Z])", "$1-$2").ToLower();
}

builder.Services.Configure<RouteOptions>(options => {
    options.ConstraintMap["kebab"] = typeof(KebabCaseParameterTransformer);
});
// Controller action 'GetProductDetails' automatically routes as /get-product-details
Real-world example
An API standardizing on kebab-case URLs (a common REST convention) applies a single global parameter transformer instead of manually annotating every controller and action with an explicit lowercase-hyphenated [Route] template.
Likely follow-ups
  • What other casing conventions might a transformer implement (snake_case, etc.)?
  • How does this interact with minimal APIs, which don't use PascalCase action names the same way?
Controllers vs Minimal APIs RESTful Web APIs & Controllers
Q13 Advanced Save

How would you debug why a specific request isn't matching the route you expect it to, using ASP.NET Core's routing diagnostics?

Enabling debug-level logging for the Microsoft.AspNetCore.Routing category reveals detailed information about route matching attempts, including which candidate routes were considered and why they were rejected (constraint mismatch, missing required parameter) -- combined with inspecting HttpContext.GetEndpoint() to confirm exactly which endpoint (if any) actually matched, this is the primary diagnostic path for tracking down unexpected routing behavior.
// appsettings.Development.json
{
  "Logging": {
    "LogLevel": {
      "Microsoft.AspNetCore.Routing": "Debug"
    }
  }
}
// Logs will show candidate routes evaluated and why each was accepted/rejected
Real-world example
A developer confused why a request to /products/42 was unexpectedly hitting a catch-all NotFound handler instead of the expected /products/{id:int} route enables routing debug logging, immediately revealing a typo in the route constraint syntax that was silently causing it to never match.
Likely follow-ups
  • What routing-related information does HttpContext.GetEndpoint() expose for debugging?
  • How would you write an automated test specifically verifying route matching behavior?
Diagnostics & Performance Testing ASP.NET Core Applications
Q14 Intermediate Save

How do complex/composite route segments (combining literal text and a parameter in the same segment, like {fileName}.{extension}) work?

A single URL segment can combine literal characters and multiple parameters, like {fileName}.{extension}, letting the routing system parse a segment like 'report.pdf' into fileName='report' and extension='pdf' -- though this pattern requires unambiguous delimiters (like the literal dot here) since the router needs to determine where one parameter ends and the next literal/parameter begins.
app.MapGet("/files/{fileName}.{extension}", (string fileName, string extension) => {
    // GET /files/report.pdf -> fileName = "report", extension = "pdf"
    return DownloadFile(fileName, extension);
});
Real-world example
A file-serving endpoint splits a single URL segment like 'report.pdf' into separate fileName and extension route values using a composite route segment, letting handler code work with each part independently without manual string splitting.
Likely follow-ups
  • What ambiguity issues can arise with composite segments lacking a clear literal delimiter?
  • How does this compare to just accepting the full segment as one string and splitting it manually in the handler?
File Uploads & Streaming Large Files Model Binding & Validation
Q15 Advanced Save

How would you design a route structure and constraint strategy for a large, RESTful API with deeply nested resource hierarchies (like organizations/{orgId}/projects/{projectId}/tasks/{taskId})?

Best practices include: applying appropriate type constraints (:int, :guid) on every ID segment to reject malformed requests early at the routing level rather than deep in handler validation logic, keeping nesting depth reasonable (typically no more than 2-3 levels, since very deep nesting can indicate an overly rigid API design that would benefit from flatter, more independently-addressable resources), and using route groups to apply consistent authorization/validation across an entire resource hierarchy's related endpoints.
var orgGroup = app.MapGroup("/api/organizations/{orgId:guid}").RequireAuthorization();
var projectGroup = orgGroup.MapGroup("/projects/{projectId:guid}");
var taskGroup = projectGroup.MapGroup("/tasks/{taskId:guid}");

taskGroup.MapGet("/", GetTask);
taskGroup.MapPut("/", UpdateTask);
// All levels enforce guid constraints and inherit the org-level authorization requirement
Real-world example
A project management API's deeply nested resource hierarchy consistently applies :guid constraints at every level and nests route groups to inherit authorization requirements automatically, avoiding both malformed-ID bugs and repeated boilerplate authorization checks across dozens of related endpoints.
Likely follow-ups
  • At what nesting depth does an API design usually benefit from flattening into independently addressable resources instead?
  • How do constraints at each level help catch malformed requests before any handler logic executes?
RESTful Web APIs & Controllers Authorization

Showing 11–15 of 15