How to version Web APIs (URL versioning, header versioning, media type versioning) Use Microsoft.AspNetCore.Mvc.Versioning package. ✅ Supported methods: ● URL versioning: /api/v1/products ● Header versioning: X-API-Version: 1.0 ● Media Type versioning: Accept:
Short answer: pplication/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true; options.AssumeDefaultVersionWhenUnspecified = true; options.DefaultApiVersion = new ApiVersion(1, 0); }); pplication/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true;… options.AssumeDefaultVersionWhenUnspecified…… = true; options.DefaultApiVersion = new ApiVersion(1, 0);…
Explain a bit more
}); pplication/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true; options.AssumeDefaultVersionWhenUnspecified = true; options.DefaultApiVersion = new ApiVersion(1, 0); }); pplication/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true;… options.AssumeDefaultVersionWhenUnspecified = true; options.DefaultApiVersion = new ApiVersion(1, 0); });
Real-world example (ShopNest)
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png