Should an API be aware of client versions?

Should an API be aware of a client version?

The idea of that really goes against the grain for me, but it seems like it is being pushed for in my current project.

Am I wrong? Can I get some reasons for or against this that I can present or understand why it might be good.

The API is a RESTful API.

8

An API should be as consistent as possible. Making the same call to the API should always do the same thing. Responding differently based on the client version would be unexpected and confusing. It may lead to subtle errors, as someone who upgrades a client would get different results and not know why.

Of course, you can make functions that provide different levels of data available to meet different needs. But they should be offered to everyone, and the users of the API can decide what level they want.

Almost without exception, no. Methods represent behaviors. Behaviors generally aren’t supposed to change depending on who the consumer is. For example, when you walk into a restaurant, do you expect to get treated differently because of your gender or your skin color? Of course not. The implicit contract that every restaurant makes with the world is: “You come into my restaurant, I hand you a menu from which to pick things, and you eat the thing you selected.” The fact that I might not know what one of the foods is is irrelevant. That’s MY problem, not the restaurant’s problem. The restaurant can’t become a hair salon, simply because that’s what I, as a client, want or expect. That’s one of the ways we end up with the God Object antipattern. Clearly defining client and producer responsibilities is super important in OOAD.

So, that’s the rule. There are some corner-case exceptions to it, but at the moment they aren’t coming to mind.

The problem that you can run into without the idea of supporting client version is that it becomes very difficult to change your data representations required and sent by the API. Representation changes can force client applications to change and leave them in a broken state until they do.

Not including a client version scheme makes sense if the API is reasonably static and its methods are not subject to modification, just addition.

Ideally you shouldn’t have to choose between not being able to modify the service contract and breaking clients.

The underlying code base does not necessarily have to care about the client version if you have version specific deploy points managed via an url path scheme (ie http://my.org/myservice/v1, http://my.org/myservice/v2, etc). You would have to manage multiple copies of the code with this scheme however.

1

Although I agree with @dan1111 that a server has no business acting different according to the client version, I can see a case where you add a feature to one of the APIs and:

  • You don’t want to change its name/end-point/whatever just to differentiate it from the previous version, because you plan to deprecate the previous version, and don’t want the API to suffer from long term readability or cumbersome naming for all eternity
  • You want to roll-out your new feature, but during the roll-out you have both the new client, and the old client, who does not know how to handle the new feature
  • Your planned roll-out is short term enough that you know that within X days, the old client will be (for all practical purposes) extinct

In this case, I think it is a viable strategy to add your feature in a defensive way, adding ad-hoc code to support the old client as to not break it, until your roll-out is complete.
After that period, you can safely remove the ad-hoc code, so you don’t end up with a patchy, encumbered code.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật