DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Build a REST API With Just 2 Classes in Java and Quarkus
  • Micronaut vs Spring Boot: A Detailed Comparison
  • Best Practices for Designing Resilient APIs for Scalability and Reliability
  • Designing Scalable Java APIs With GraphQL

Trending

  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  • AI's Dilemma: When to Retrain and When to Unlearn?
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Unlocking Data with Language: Real-World Applications of Text-to-SQL Interfaces
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Learn With Practice: API Versioning Snags

Learn With Practice: API Versioning Snags

In this article, review the practical approaches in API versioning, the pros and cons, as well as some basic reasons for API versioning.

By 
Anton Yarkov user avatar
Anton Yarkov
DZone Core CORE ·
Nov. 29, 22 · Opinion
Likes (1)
Comment
Save
Tweet
Share
4.2K Views

Join the DZone community and get the full member experience.

Join For Free

I have finished watching a series of lessons on Designing and Versioning HTTP/REST APIs from well-known author Jeffrey Richter, who is an author of the best-sellers CLR via C# and Windows API via C++.

Lumberjack versioning graphic

For those who design back-end APIs, I do definitely recommend watching it (and reading the books as well, if you haven't), especially those who think that doing an API is simple (probably, impressed by several "Hello, World!" prototypes made during the weekends).

One important thing to note in this article is that it is really important to combine some practice when you do theoretical learning.

This recommendation will work for developers of any level of experience and does not depend on how well-known the author of the book/course is. It is always easy to watch and read something and put a sign "learned" on it, but actual implementation will always put some impediments, and this is where things get really interesting.

Now, let's take one piece of advice from the course, and let's dive into the part that covers the topic of versioning HTTP APIs.

REST API Everywhere

Most of the public APIs go with REST or RESTful approaches. Those gRPC, SOAP, GraphQL and other protocols are good for their own purposes, but REST is covering most of the needs:

  • It's available for any type of client: old/new browsers, smartphones, low-end computers, Raspberry Pis, and even consoles.
  • It uses well-known HTTP language for all the features that an API needs, like handling errors, passing auth tokens (headers), transferring all types of content, bandwidth control, etc.
  • Many examples are available on the internet 

And, truly saying, for prototypes and local businesses, quick and cheap development is all you need. All other protocols have been created to solve much more specific needs like scaling, handling low-bandwidth channels, enterprise solutions, etc.

But this simplicity and low entry threshold play a bad role when it comes to the product quality of your public API. Very few non-senior developers know that public APIs must be backward compatible and sometimes even forward compatible. A tiny portion of developers knows how to achieve it. 

What’s Wrong With Public APIs?

API versioning plays a crucial role in making your API really desirable for your happy clients. Since you published your API for the first time, things never have been fun for you.

You have to maintain all the bases of the clients from version 1.0-pre-alpha until version 99999...9.0, unless you have been smart enough to publish your public API policy of use. Didn't you? :)

In this policy, you can recommend all your clients to update on every release, but it's still just a recommendation. You can also not guarantee the stability of your old versions, but that really depends on your customer relationships.

In any way, you have to label your API version and make sure that clients potentially understand how it works based on the documentation and policies that you have provided.

Just Follow Someone’s Recommendations in API Versioning: What Can Go Wrong?

An API version is a label that should tell your clients what to expect. There are various ways of doing so, to mention a few:

  • http://api.tactica.xyz/products?api-version=0.1-alpha
  • http://api.tactica.xyz/products?api-version=1.0
  • http://api.tactica.xyz/products?api-version=2023-01-01
  • http://api.tactica.xyz/v0.9-beta/products
  • http://api.tactica.xyz/v1.0/products

As you can see, there are many ways to tell your API version to the client, and before you take the first approach in the list, I should tell you that it's not always "up to you." Let's review why you may want to use one or another way.

Basically, there are only 2 approaches that differ significantly:

  1. Put your API version in the URL.
  2. Put your API version in the parameters.

In various sources, I've seen approach #1 marked as outdated. However, there are still reasons to keep using it. Let's review those.

Why Pass a Version in the URL

  • Most of the API Management systems do use "API version in the URL" as a default approach, such as Axway, MuleSoft Anypoint, Google Apigee, Boomi, AWS API portal, and Nginx API Management.
  • Services co-located behind a DNS endpoint MUST use the same versioning mechanism, so if you already have something (maybe legacy) versioned this way, you better stick with it.

Why Pass a Version as a Parameter

  • We can guarantee the stability of their REST API's URL paths, even through future versions of the API.
  • You can always return a DEFAULT resource without a version even specified. etc.
  • Easily change from -preview or -beta to the released and thus, make your development a bit more agile and iterative.
  • Gives more transparency to the clients -> more information on the date of release
  • Split out API BEHAVIOR from RESOURCE.
  • Support the Group Versioning feature that allows developers to look up a single version number and use it across multiple endpoints. Group version numbers are well-known, and services should reject any unrecognized values.

Phew. Quite a few notes, ha?

The fun thing is that nothing of that is actually mentioned in the course. That's why I wanted to bring this example of the need for questions, which appear right after you start practicing.

More To Consider for Public API

The approach to API versioning should not be an afterthought. Each time you want to change a mandatory parameter, the payload format, replace some old error codes, or change a behavior, consider adding new API methods and publishing new versions.

It would be even better if you embed version numbers in the data structure. You may not need that in the beginning, but you will thank yourself when you want to scale (event-driven architecture, etc.).

Conclusion

Following those rules will make your public API clients happier and your life a bit easier (but is a lot, still).

As you may notice, in general, there are many "up to you"s in the API versioning, starting from policies and right to the technical details, but that is not usually part of any book or a course and this is something you have to solve on your own. 

Next time, before finishing your training course, take your time to practice a little bit. I'm sure you will find many places to raise a hand and discuss with your experienced colleagues or a community.

API REST

Published at DZone with permission of Anton Yarkov. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Build a REST API With Just 2 Classes in Java and Quarkus
  • Micronaut vs Spring Boot: A Detailed Comparison
  • Best Practices for Designing Resilient APIs for Scalability and Reliability
  • Designing Scalable Java APIs With GraphQL

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!