Advertisement
Advanced ASP.NET Core, API Versioning

How does ASP.NET Core API versioning handle a request that doesn't specify any version at all?

Short answer

Behavior depends on configuration: setting AssumeDefaultVersionWhenUnspecified = true combined with DefaultApiVersion routes unversioned requests to a designated default version transparently; without that setting, an unversioned request to a versioned endpoint typically results…

Save ASP.NET Core mock interview
Advertisement
AModel answer
Behavior depends on configuration: setting AssumeDefaultVersionWhenUnspecified = true combined with DefaultApiVersion routes unversioned requests to a designated default version transparently; without that setting, an unversioned request to a versioned endpoint typically results in a 400 Bad Request indicating an API version is required -- the choice reflects a trade-off between convenience for simple/internal clients versus explicitness that avoids silently locking clients into a version they didn't deliberately choose.
builder.Services.AddApiVersioning(options => {
    options.DefaultApiVersion = new ApiVersion(1, 0);
    options.AssumeDefaultVersionWhenUnspecified = true;  // unversioned requests silently get v1.0
});

// Without AssumeDefaultVersionWhenUnspecified:
// An unversioned request instead returns 400 Bad Request
Real-world example
A public API deliberately disables AssumeDefaultVersionWhenUnspecified, forcing every client to explicitly declare a version, preventing a scenario where an unversioned client silently continues receiving v1 responses forever without realizing newer versions exist.
Likely follow-ups
  • What's the risk of silently defaulting unversioned requests to the latest version instead of a fixed default?
  • How do public versus internal APIs typically differ in this choice?
Related topics