当前位置:网站首页>Step by step evolution of restful API version Frankel
Step by step evolution of restful API version Frankel
2022-06-12 22:05:00 【Solution jdon】
Design an intuitive 、 User friendly RESTful API It's a hard job . If this is your first attempt , This may already be a difficult task . planning API Life cycle management may be an afterthought . But it is possible anyway : In this article , I want to propose a serious way to develop your API, Even if it has no plans .
Let's assume that one says “Hello” The sample application for :
> curl http://org.apisix/hello Hello world > curl http://org.apisix/hello/Joe Hello Joe |
Use API gateway
The first and most critical step is to stop exposing applications directly to the Internet , And build a API gateway .
Versioning API
evolution API signify API Multiple versions of need to coexist at some point .
Three methods :
curl http://org.apisix/hello?version=1 curl http://org.apisix/hello?version=2 curl -H 'Version: 1' http://org.apisix/hello curl -H 'Version: 2' http://org.apisix/hello curl http://org.apisix/v1/hello curl http://org.apisix/v2/hello |
At this stage , We have configured two routes , One is versioned , The other is non versioned :
> curl http://org.apisix/hello Hello world > curl http://org.apisix/v1/hello Hello world |
Migrate users from non versioned paths to versioned paths
We're right API Version control is in place , But our users may still be using old non versioning API. We want them to move , But we can't just delete old routes , Because our users don't know it . Fortunately, ,301 HTTP The status code is our friend : We can let users know that the resources have changed from http://org.apisix/hello Moved to http://org.apisix/v1/hello. It needs to be configured on the initial route Redirection plug-ins :
curl http://apisix:9080/apisix/admin/routes/1 -H 'X-API-KEY: xyz' -X PATCH -d '
{
"plugins": {
"redirect": {
"uri": "/v1$uri",
"ret_code": 301
}
}
}'
|
It turns out to be interesting :
Either the user will use the new endpoint transparently , Because they will follow , Or their integration is interrupted , They will notice 301 Status and new to use API Location .
Know your users
You may have noticed , up to now , We don't know who is using our API. When we have to introduce change , We have to be creative , Do not destroy the user's use . Other changes may not be so easy to deal with . therefore , We should try to understand our users , In order to contact them if necessary .
Create user
You should probably start seeing your users visit the registration page , Depending on how much you limit unauthenticated usage . There are many ways to register ; There may be :
- Automate or require as many manual verification steps as possible
- Free or paid
- It's as simple as asking for an email without further verification , Or as complex as needing more data
- wait .
It depends on your situation .
Production testing
At this stage , We are now ready to let users know about our Hello world API Improved version . I assume that our team has thoroughly tested it , But new code is always risky . Deploying a flawed new version of an existing application may be beneficial to API The image of the provider ( And income !) Have a negative impact .
Discard old version
Most users may migrate to the new version to benefit from it , But a small part of it will remain v1.1 On . There may be several reasons for this : There is no suitable time ( Tips : It will never )、 Too expensive 、 There is not enough migration power , wait . But as a API Provider , Each deployed version has a cost . You may need to deactivate... At some point v1.
Conclusion
In this article , We described a simple step-by-step process to manage API Life cycle of :
- Don't expose your API; Set one in front API gateway
- Use path 、 Query parameter or request header pair existing API Version control
- Migrate users from an unversioned endpoint to one with 301 Versioned endpoint of state code
- Gently push your user to register
- Test in production , First, copy the traffic , Then transfer a small number of users to the new version
- Official release of new version
- Deprecation of older versions is communicated through standard response headers
Click on the title for details
The complete source code of this article can be found in Github In order to maven Format found .
API Version control related articles :
- https://stripe.com/blog/api-versioning
- https://apisyouwonthate.com/blog/api-evolution-for-rest-http-apis
- https://apigility.org/documentation/api-primer/versioning
边栏推荐
- SQL调优指南笔记12:Configuring Options for Optimizer Statistics Gathering
- 【QNX Hypervisor 2.2 用户手册】4.3 获取host组件
- PE installation win10 system
- Semester summary of freshman year
- Yyds dry inventory insider news: Series high-frequency interview questions, worth a visit!
- Configuring Dingding notification of SQL audit platform archery
- June training (day 11) - matrix
- SQL调优指南笔记9:Joins
- 【图像去噪】基于三边滤波器实现图像去噪附matlab代码
- Unity 常用3D数学计算
猜你喜欢

Recommended Chinese font in the code input box of Oracle SQL developer

【概率论与数理统计】期末复习抱佛脚:公式总结与简单例题(完结)

SQL tuning guide notes 11:histograms

Jin AI her power | impact tech, she can

多线程模型下的生产者消费者模式
![[probability theory and mathematical statistics] final review: formula summary and simple examples (end)](/img/f5/1c8392aaf87ea323524e94e3f213ed.png)
[probability theory and mathematical statistics] final review: formula summary and simple examples (end)

SQL tuning guide notes 15:controlling the use of optimizer statistics

MySQL introduction and installation (I)

Preliminary use of jvisualvm

Ansible-大总结(六)
随机推荐
[qnx hypervisor 2.2 manuel de l'utilisateur] 4.2 environnement de construction pris en charge
How to ensure thread safety?
【QNX Hypervisor 2.2 用户手册】4.4 构建Host
[Jianzhi offer] Jianzhi offer 09 Implementing queues with two stacks
Unity 常用3D数学计算
[simple] 155 Minimum stack
在同花顺开户证券安全吗,证券开户怎么开户流程
动态规划之如何将问题抽象转化为0-1背包问题(详解利用动态规划求方案数)
Economist focuses on WTO MC12: digital economy may become an important issue
How to write a vscode plug-in by yourself to realize plug-in freedom!
"Oracle database parallel execution" technical white paper reading notes
A puzzle about + =
SQL tuning guide notes 9:joins
SQL tuning guide notes 8:optimizer access paths
Ansible playbook and ansible roles (III)
Oracle 19C installation documentation
六月集训(第10天) —— 位运算
Preliminary use of jvisualvm
leetcodeSQL:574. Elected
[Jianzhi offer simple] Jianzhi offer 06 Print linked list from end to end