- Hands-On RESTful Web Services with TypeScript 3
- Biharck Muniz Araújo
- 553字
- 2021-07-02 12:19:22
Versioning
As APIs are being developed, gathering more business rules for their context on a day-to-day basis, generating tech debits and maturing, there often comes a point where teams need to release breaking functionality. It is also a challenge to keep their existing consumers working perfectly. One way to keep them working is by versioning APIs.
Breaking changes can get messy. When something changes abruptly, it often generates issues for consumers, as this usually isn't planned and directly affects the ability to deliver new business experiences.
There is a variant that says that APIs should be versionless. This means that building APIs that won't change their contract forces every change to be viewed through the lens of backward compatibility. This drives us to create better API interfaces, not only to solve any current issues, but to allow us to build APIs based on foundational capabilities or business capabilities themselves. Here are a few tips that should help you out:
- Put yourself in the consumer's shoes: When it comes to product perspective, it is suggested that you think from the consumer's point of view when building APIs. Most breaking changes happen because developers build APIs without considering the consumers, which means that they are building something for themselves and not for the real users' needs.
- Contract-first design: The API interface has to be treated as a formal contract, which is harder to change and more important than the coding behind it. The key to API design success is understanding the consumer's needs and the business associated with it to create a reliable contract. This is essentially a good, productive conversation between the consumers and the producers.
- Requires tolerant readers: It is quite common to add new fields to a contract with time. Based on what we have learned so far, this could generate a breaking change. This sometimes occurs because, unfortunately, many consumers utilize a deserializer strategy, which is strict by default. This means that, in general, the plugin that's used to deserialize throws exceptions on fields that have never been seen before. It is not recommended to version APIs, but only because you need to add a new optional field to the contract. However, in the same way, we don't want to break changes on the client side. Some good advice is documenting any changes, stating that new fields might be added so that the consumers aren't surprised by any new changes.
- Add an object wrapper: This sounds obvious, but when teams release APIs without object wrappers, the APIs turn on hard APIs, which means that they are near impossible to evolve without having to make breaking changes. For instance, let's say your team has delivered an API based on JSON that returns a raw JSON array. So far, so good. However, as they continue, they find out that they have to deal with paging, or have to internationalize the service or any other context change. There is no way of making changes without breaking something because the return is based on raw JSON.
- Always plan to version: Don't think you have built the best turbo API in the world ever. APIs are built with a final date, even though you don't know it yet. It's always a good plan to build APIs while taking versioning into consideration.
- 哮喘患者自我管理手冊(cè)
- 實(shí)用口腔正畸臨床技術(shù)圖譜
- 眼科手術(shù)器械清洗消毒滅菌技術(shù)操作規(guī)程
- 中國(guó)神經(jīng)介入發(fā)展史
- 孕育優(yōu)質(zhì)寶寶的12堂成功課
- 顧嘉雄 張良圣醫(yī)案精華
- 實(shí)用化學(xué)藥品檢驗(yàn)檢測(cè)技術(shù)指南
- 血液病臨床診療精要
- 產(chǎn)前超聲檢查規(guī)范解讀
- 中醫(yī)臨床技能實(shí)訓(xùn)教程
- 拯救孩子視力(第三版)
- 中西醫(yī)專家?guī)湍庾x痤瘡
- 學(xué)習(xí)睡覺(jué)
- 急危重癥容量管理
- 結(jié)直腸癌老年患者治療與康復(fù)