codecamp

1 Why we need API design and documentation

来源:http://afoo.me/posts/2015-03-17-api-design-and-documentation.html
作者:陨石 - yunshi@wacai.com

HTTP API (现在很多地方都使用REST API这个术语, 不过注意这里使用的是HTTP API,至于为什么, 嘿嘿,自己意会吧 ;-)↩) can't be typesafe as per the http protocol's essential, so we need to find a way so that the api providers and consumers can come to the same rendzvous point with proper constraits and clarity.

HTTP协议的特性决定了基于HTTP的API属于松散类型(与强类型或者说类型安全的API相对应), 为了能够让API的提供者和消费者可以一种双方都可以明晰且明确的方式达成共识, 我们需要找到一种方式来描述API,以便对双方进行一定的约束,从而形成一种双方都可以遵守的契约式的协议, 在某些层面增加少许工作量的同时,为双方提供便利和参考。

2 How API design and documentation work
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }