asp.net core api versioning

12

Click here to load reader

Upload: shawn-wildermuth

Post on 22-Jan-2018

128 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: ASP.NET Core API Versioning

Shawn Wildermuth

One of the Minds, Wilder Minds LLC

Microsoft MVP

@shawnwildermuth

http://wilderminds.com

Versioning APIs with ASP.NET Core

Page 2: ASP.NET Core API Versioning

Versioning APIs with ASP.NET Core © 2015-2017 Wilder Minds LLC

Who Am I?

Author

– Eight books and Lots of Articles on .NET and Software Development

Podcast

– hwpod.com

Instructor

– Over twenty courses for Pluralsight including:

Building a Web App with ASP.NET Core, EF Core, Bootstrap and Angular

– http://shawnw.me/psauthor

Page 3: ASP.NET Core API Versioning

Versioning APIs with ASP.NET Core © 2015-2017 Wilder Minds LLC

What Is API Versioning?

Once you publish an API, it's set in stone

– Users/Customers rely on the API not changing

– But requirements will change

– Need a way to evolve the API without breaking existing clients

– API Versioning isn't Product Versioning

Don't tie them together

Page 4: ASP.NET Core API Versioning

Versioning APIs with ASP.NET Core © 2015-2017 Wilder Minds LLC

The Problem with API Versioning

In typical projects

– Versioning is accomplished with different versions of the package

E.g. Assemblies

API versioning is harder

– Your API needs to support both new and old users

– Side-by-side deployment isn't feasible most of the time

– Need to support both versions in same code base

Page 5: ASP.NET Core API Versioning

Versioning APIs with ASP.NET Core © 2015-2017 Wilder Minds LLC

API Versioning Schemes

There are lots of ways to version an API

– Not all of them are recommended

– If you find a mechanism that works for you, that’s all that matters

– But remember that you’re serving your clients, not yourselves

Page 6: ASP.NET Core API Versioning

Versioning APIs with ASP.NET Core © 2015-2017 Wilder Minds LLC

Versioning in the URI

// URI Pathhttps://foo.org/api/v2/Customers

// Query Stringhttps://foo.org/api/Customers?v=2.0

Page 7: ASP.NET Core API Versioning

Versioning APIs with ASP.NET Core © 2015-2017 Wilder Minds LLC

Versioning with Headers

GET /api/camps HTTP/1.1Host: localhost:44388Content-Type: application/jsonX-Version: 2.0

Page 8: ASP.NET Core API Versioning

Versioning APIs with ASP.NET Core © 2015-2017 Wilder Minds LLC

Versioning with Accept Header

GET /api/camps HTTP/1.1Host: localhost:44388Content-Type: application/jsonAccept: application/json;version=2.0

Page 9: ASP.NET Core API Versioning

Versioning APIs with ASP.NET Core © 2015-2017 Wilder Minds LLC

Versioning with Content Type

GET /api/camps HTTP/1.1Host: localhost:44388Content-Type: application/vnd.yourapp.camp.v1+jsonAccept: application/vnd.yourapp.camp.v1+json

Page 10: ASP.NET Core API Versioning

Versioning APIs

Demo

Page 11: ASP.NET Core API Versioning
Page 12: ASP.NET Core API Versioning

Versioning APIs with ASP.NET Core © 2015-2017 Wilder Minds LLC

Takeaways…

Important Links

– ASP.NET Core: dot.net

– ASP.NET Core’s Source: github.com/aspnet/home

My ASP.NET Core Course:

– http://shawnw.me/corewebapi