用于通知客户已弃用的API

用于通知客户已弃用的API

本文介绍了HTTP响应标头的约定,用于通知客户已弃用的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在升级我们的REST API端点,并且我想在他们调用要弃用的端点时通知客户端。

我应该在响应中使用什么标头,并在行中显示消息此API版本已被弃用,请参阅最新文档以更新您的终端

I'm upgrading our REST API endpoints and I want to notify clients when they are calling the to-be-deprecated endpoint.
What header should I use in the response with a message along the lines of "This API version is being deprecated, please consult the latest documentation to update your endpoints"

推荐答案

我不会改变任何内容要向后兼容的状态代码。我会在响应中添加一个警告标题:

I would not change anything in the status code to be backward compatible. I would add a "Warning" header in the response :

Warning: 299 - "Deprecated API"

您还可以使用发出警告的代理指定 - ,并在警告文本中更明确:

You can also specify the "-" with the "Agent" that emits the warning, and be more explicit in the warn-text :

Warning: 299 api.blazingFrog.com "Deprecated API : use betterapi.blazingFrog.com instead. Old API maintained until 2015-06-02"

此处指定警告标题:。 Warn-code 299是通用的,Deprecated不是标准的。

Warning header are specified here : https://tools.ietf.org/html/rfc7234#section-5.5. Warn-code 299 is generic, "Deprecated" is not standard.

您必须告诉您的API客户端记录HTTP警告并监控它。

You have to tell your API clients to log the HTTP warnings and monitor it.

我从未使用过它,但是当我的公司在Rest API中更成熟时,我会整合它。

I've never used it until now, but when my company will be more mature in Rest API I will integrate it.

这篇关于HTTP响应标头的约定,用于通知客户已弃用的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 21:39