Menu

Rest service versioning strategy

3 Comments

rest service versioning strategy

The canonical reference for building a production grade API with Spring. Evolving a REST API is a difficult problem — one for which many options are available. This article discusses through some of these options. Before anything else, we need to answer one simple question: What is the Contract between the API and the Client? Should clients bookmark, hardcode and generally rely on URIs of the API? If they would, then the interaction of the Client with the REST Service would no longer be driven by the Service itself, but by what Roy Fielding calls out-of-band information:. A REST API should be entered with no prior knowledge beyond the initial URI bookmark and set of strategy media types that are appropriate for the intended audience…Failure here implies that out-of-band information is driving interaction instead of hypertext. So clearly URIs are not part of the contract! The client should only know a single URI — the entry point to the API — all other URIs should be discovered while consuming the API. What about the Media Type information used for the representations of Resources — are these part of the contract between the Client and the Service? In order to successfully consume the API, the Client must have prior knowledge of these Media Types — in fact, the definition of these media types represents the entire contract, and is where the REST Service should focus the most:. So the Media Type definitions are part of the contract and should be prior knowledge for the client that consumes the API — this is where standardization comes in. When we introduce the version in the URI spacethe Representations of Resources are considered immutable, so when changes need to be introduced in the API, a new URI space needs to be created. For examplesay an API publishes the following resources — users and privileges:. When we version the Media Type and extend the languagewe go through Content Negotiation based on this header. It is these media types that are going to be versioned instead of the URIs. What is important to understand here is that the client makes no assumptions about the structure of the response beyond what is defined in the media type. This is why generic media types are not ideal — these do not provide enough semantic information and force the client to use require additional hints to process the actual representation of the resource. An exception to this is using some other way of uniquely identifying the semantics of the content — such as an XML schema. First, introducing version identifiers in the URI leads to a very large URI footprint. This is due to the fact that any breaking change in any of the published APIs will introduce a whole new tree of representations for the entire API. Over time, this becomes a burden to maintain as well as a problem for the client — which now has more options to choose from. Version identifiers in the URI is also severely inflexible — there is no way to simply evolve the API of a single Resource, or a small subset of the overall API. As rest mentioned before, this is an all or nothing approach — if part of the API moves to the new version, then the entire API has to move along with it. This also makes upgrading clients from v1 to v2 a major undertaking — which leads to slower upgrades and much longer sunset periods for the old versions. From the perspective of proxy caches in the middleeach approach has advantages and disadvantages: This puts load service the cache and decreases the cache hit rate, since different clients will use different versions. Also, some cache invalidation mechanisms will no longer work. If the media type is the one that is versioned, then both the Client and the Service need to support the Vary HTTP header to indicate that there are multiple versions being cached. From the perspective of client caching however, the solution that versions the media type involves slightly more work than the one where URIs contain the version identifier. Now, adding information in the Versioning of a resource will not break existing clients if these are correctly implemented. Removing, renaming or generally restructuring information in the design of existing representations is a breaking change for clients, because they already versioning and rely on the old rest. This is where Content Negotiation comes in — for such changes, a new vendor MIME media type needs to be introduced. As such, this does represent an incompatible change for the Client — which will have to request the new Representation and understand the new semantics, but the URI space will remain stable and will not be affected. These are changes in the meaning of the Service, the relations between them or what the map to in the backend. This kinds of changes may require a new media type, or they may require publishing a new, sibling Resource next to the old one and making use of linking to point to it. While this sounds like using version identifiers in the URI all over again, the important distinction is that versioning new Resource is published independently of any other Resources in the API and will not fork the entire API at the root. Changing such an URI should not be considered an incompatible change — the new URI can replace the old one and Clients will be able to re-discover the URI and still function. It is worth noting however that, while using version identifiers in the URI is problematic for all of these reasons, it is not un-RESTful in any way. This article tried to provide an overview of the very diverse and difficult problem of evolving a REST Service. We strategy the two common solutions, advantages and disadvantages of each one, and ways to reason about these approaches in the context of REST. The article concludes by making the rest for the second solution — versioning the media typeswhile examining the possible changes to a RESTful API. Usually these reading resources are linked throughout the article, but in these case, there are simply to many service ones:. Build your Microservice Architecture with. Spring Strategy and Spring Cloud. With the hateoas links in a response how should you indicate that a versioned media type should be sent n the request? I suppose that if the client was smart enough to supply it they will do it for the next request. The media types are the only part that the client needs to have prior knowledge of. Check out the part about media types above. REST with Spring The canonical reference for building a production grade API with Spring. Persistence The main persistence with Spring guides here at Baeldung. REST The main guides on REST APIs with Spring, here at Baeldung. Security The main Spring Security guides here at Baeldung. Full Archive The high level overview of all the articles on the site. About Baeldung About Baeldung. Versioning a REST API Last modified: July 20, by Eugen Paraschiv. The new Certification Class of REST With Spring is out: Go deeper into building a REST API with Spring: Build your Microservice Architecture with Spring Boot and Spring Cloud. Seems legit to me. Categories Spring REST Java Security Persistence Jackson HttpClient. About About Baeldung The Courses Meta Baeldung The Full Archive Write for Baeldung Privacy Policy Terms of Service Contact Company Info.

Versioning Your API

Versioning Your API rest service versioning strategy

3 thoughts on “Rest service versioning strategy”

  1. AdrianNight says:

    You would have never imagined is the strip patterns, which have very a cartoon feeling, canada goose femme:, could be put in the leading brim of fashion plus looked exceedingly fashionable.

  2. style says:

    Sakuni was an expert at false dice, and challenged Yudhishthir, and Yudhishthir held it a point of honour not to decline such a challenge.

  3. affiliate says:

    Comte, which has great beauty and grandeur in it, and the realization of which, within the bounds of possibility, would be a cultivation of the social feelings on a most essential point.

Leave a Reply

Your email address will not be published. Required fields are marked *

inserted by FC2 system