网站 API 的黄金标准是什么? 推特、Flickr、脸书等

发布于 2024-07-09 11:58:44 字数 1454 浏览 10 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

幻梦 2024-07-16 11:58:44

我们自己也在这方面做一些研究。 网站 API 参考的“黄金标准”并不多。

最常见的网站 API 引用有:

这里的另一个列表:

http:// /www.pingable.org/the-top-15-web-apis-for-your-site/

有人推荐了这本书Restful Web Services 作为这方面的一个很好的参考。

(请随意编辑上面的列表以添加其他具有 API 的知名网站)

We're doing some research in this area ourselves. Not a lot out there in terms of "gold standard" for website API references.

The most common website APIs referenced are:

Another list here:

http://www.pingable.org/the-top-15-web-apis-for-your-site/

Someone recommended the book Restful Web Services as a good reference on this.

(please feel free to edit the above list to add other high profile websites with APIs)

蹲在坟头点根烟 2024-07-16 11:58:44

如何设计良好的 API 及其重要性,由 < 主持的 60 分钟 Google 技术讲座a href="http://en.wikipedia.org/wiki/Joshua_Bloch" rel="noreferrer">Joshua Bloch 是相关的。

How To Design A Good API and Why it Matters, a 60 minute Google tech talk by Joshua Bloch, is relevant.

寄意 2024-07-16 11:58:44

与一些人合作后,我会立即着手

  • Facebook

    • 好:干净且相对一致。 表现良好,大多数事情在逻辑上都是有意义的。 FQL 非常简洁。 XML 和 JSON 选项。 除了您真正需要的之外,不要预先构思响应格式
    • 不好:经常更改且没有任何警告。 “官方”API 库非常糟糕。 许多通话的记录很差或丢失。 非标准身份验证(有些人可能认为这很好?)
  • Myspace

    • 优秀:开放标准(oAuth 身份验证、Opensocial 端点)
    • 坏:经常损坏。 oauth 的使用非常不标准,并且会破坏大多数客户端库。 官方客户端库很糟糕。
  • Photobucket(免责声明:我编写了 photobucket api 的服务器端)

    • GOOD:开放标准身份验证 (oauth)。 xml、json、甚至php序列化数组格式作为响应参数。 忠实的 REST(在“名词”网址上获取/放置/删除/发布)。
    • 不好:客户端库不多。 标准 oauth 库的架构挑战(用户生活在子域中,必须调用子域,因此 url 必须更改)。
  • 推特

    • 好:非常一致(尽管 api 与搜索 api 有差异)。 良好的休息习惯。 OAuth 身份验证以及支持 oldschool Basic。
    • BAD:错误率(与 Twitter 的其余部分基本一致)。 某些返回值的格式奇怪(例如日期格式)。

理想的特征

  • 我并不认同“严格”的休息。 PUT 和 DELETE 在某些客户端语言中会导致问题。 GET 和 POST 似乎只要使用适当的“动词”就足够了。 另外,类似 RPC 的函数名称对我来说没问题,只要它们符合逻辑,甚至可能是 URI 的一部分。 在这种情况下,对象 IDS 仍然需要非常一致。
  • 标准身份验证/授权。 Basic/Digest 还可以,但我是 OpenID/oAuth 的粉丝(如果你想获得前沿技术,可以使用 WRAP)。 自己开发意味着您必须 100% 地解释它,并可能为每个人编写客户端库。
  • 标准数据类型。 确保数据类型一致(“true”或 1,而不是某种混合),并支持最通用的标准。 日期时间应为 ISO8601。 地理位置应该“看起来像”GeoRSS 等。您应该能够为您的返回类型创建 XSD/relaxNG/任何严格的验证器。 期望您的输入具有相同的标准。
  • 简单的返回结构。 XML-RPC/JSON-RPC 有一些好处,因为你有点知道你要返回什么,但无论如何,如果我无法轻松地使用 JSON 或 PHP 的 SimpleXML 之类的东西解析你的返回类型,并本质上将其序列化为一致的哈希,我会生气的。
  • 支持无破损扩展/扩展。 不要将自己的代码逼入角落,以免难以添加到 API 中。 尝试预先做出正确的决定,这样你就不会不断改变。
  • 文档! 确保其良好,并解释一切。 即使这样,它也还不够好,所以请确保您有专门的时间来处理它,并有一个支持论坛或其他任何东西来保持它的最新状态。

话虽这么说……Facebook 和 Twitter 之间的某种东西。 当然,我偏爱 Photobucket 上的一些内容,但我也讨厌其中的一些内容。

Having worked with a few, I'll get right down to it

  • Facebook

    • GOOD: clean and relatively consistent. Performs well and most things logically make sense. FQL is pretty neat. XML and JSON options. No pre-conception of response format other than what you really need
    • BAD: Changes often and without warning. 'official' api libraries are pretty atrocious. documentation of many calls are poor or missing. Non-standard authentication (some may call this good?)
  • Myspace

    • GOOD: open standards (oAuth authentication, Opensocial endpoint)
    • BAD: often broken. Usage of oauth is very nonstandard and breaks most client libraries. official client libraries are terrible.
  • Photobucket (disclaimer: I wrote the server side of the photobucket api)

    • GOOD: open standard authentication (oauth). xml, json, even php serialized array format as response parameters. faithful REST (get/put/delete/post on 'noun' urls).
    • BAD: not many client libraries. Architectural challenges with standard oauth libraries (users live on subdomains, calls must be made to subdomain, so url has to change).
  • Twitter

    • GOOD: pretty consistent (though api vs search api has diffs). Good REST practice. OAuth authentication as well as supporting oldschool Basic.
    • BAD: error rate (pretty much consistent with rest of twitter though). Odd format of some return values (like their date format).

Ideal characteristics

  • I'm not sold on 'strict' REST. PUT and DELETE cause problems in some client languages. GET and POST seem to be sufficient with appropriate 'verbs'. Also, RPC-like function names are OK with me as long as they're logical and maybe even part of the URI. In that case, object IDS still need to be very consistent though.
  • Standard authentication/authorization. Basic/Digest can be ok, but I'm a fan of OpenID/oAuth (or WRAP if you want to get bleeding edge). Rolling your own means you have to explain 100% of it, and potentially write client libraries for everyone.
  • Standard datatypes. Make sure you are consistent about your datatypes (either 'true' or 1, not some mix), and support the most generic standards. Datetime should be ISO8601. Geolocation should 'look like' GeoRSS, etc. You should be able to create an XSD/relaxNG/whatever strict validator for your return types. Expect the same standards from your inputs.
  • Simple return structure. there's some benefit to XML-RPC/JSON-RPC in that you kinda know what you're getting back, but in any case, if I cant easily parse your return type with JSON or something like PHP's SimpleXML and essentially serialize it to a consistent hash, I'm going to be pissed.
  • Support extension/expansion without breakage. Dont code yourself into a corner and make it hard to add to your API. Try to make good decisions up front that you wont be changing constantly.
  • Documentation! Make sure its good, and explains everything. Even then it won't be good enough, so make sure you have dedicated time to work on it and a supporting forum or whatever to keep it up to date.

So that being said... something between Facebook and Twitter. Of course I'm partial to some of the stuff we have on Photobucket, but I also hate some of it.

苹果你个爱泡泡 2024-07-16 11:58:44

在我看来,API 的文档与 API 的实际设计一样(或更重要)重要。

写得好的、简单的文档将弥补任何设计缺陷。 这就是我在查看已经发布的各种链接后了解到的内容。 具体来说,Last.fm 的文档看起来非常好:易于导航且易于理解。

It would seem to me that the documentation of the API is just as (or more) important than the actual design of the API.

Well written, simple documentation will make up for any design flaws. That's what I've learned after looking at the various links posted already. Specifically, Last.fm's documentation seems very good: easy to navigate and easy to understand.

梦魇绽荼蘼 2024-07-16 11:58:44

Last.fm 的 api 仍然是网络上维护得最好的 api 之一。 它的存在时间也比大多数产品都要长,因为它一开始基本上就是这样。

http://www.last.fm/api

Last.fm's api continues to be one of the most well maintained apis on the net. It's also been around longer than most, because it started out basically as just that.

http://www.last.fm/api

别忘他 2024-07-16 11:58:44

关于 Jeff 的大型 API 列表:我非常确定commonnot意味着“黄金标准”

无需保留广泛使用的 API 的手动列表。 要获取列表,请查看 http://www.programmableweb.com/apis/目录/1?sort=mashups

由于我喜欢 REST 作为宽松的标准,因此当 API 有意义直观时,我会说 API 是“黄金”。

...所有这些对我来说最有意义并且经过深思熟虑(正如布莱恩已经指出的那样)。

在我目前的日常工作中,我也经常使用 OpenSocial,其中 URI 感觉非常自然,而且还以自己的方式扩展了 REST 标准。

如果您喜欢严格且安全,请使用 SOAP。

Regarding Jeff's list of big APIs: I am pretty sure that common does not mean "Gold Standard".

No need to keep a manual list of widespread API. To get a list check out http://www.programmableweb.com/apis/directory/1?sort=mashups .

Since I like REST as loose standard, I'd say that an API is "Golden" when it makes sense and is intuitive.

… all make the most sense for me and are well thought out (as Brian already pointed out).

In my current daily work I also work a lot with OpenSocial, where URIs feel very natural but also extend the REST standard in its own way.

If you like it strict and safe, use SOAP.

赠佳期 2024-07-16 11:58:44

我会查看 OpenSocial,这是一项为社交网络服务创建 API 标准的运动。 他们为此使用 REST,并采用以“用户”为中心的方法。 但这是一种有据可查的方法,即使对于不完全基于社交的网站也可能有所帮助。 如果您正在寻找一些内部代码实现,请查看 Drupals 挂钩系统和 Wordpress。

http://code.google.com/apis/opensocial/

I would check out OpenSocial, a movement to create an API Standard for social network sices. They use REST for this and have a 'user' centric approach. But this is a very well documented approach which might help for even a site that is not totally Social based. If you are looking for some internal code implementations look at Drupals hook system and Wordpress.

http://code.google.com/apis/opensocial/

走野 2024-07-16 11:58:44

我认为最好的回答方法是列出优秀 Web API 的特征,而不是引用示例。 如果您喜欢 Twitter/Facebook/等 API,您认为这些 API 的哪些方面有吸引力?

我将首先尝试:

  1. 记录良好的 API,包括约束和使用策略。 这使得快速开发充满信心,而不是事后猜测参数可能意味着什么以及返回值是什么。
  2. 与技术/语言无关的 API。 好的 API 应该易于使用,在多种语言和平台上提供相同的功能。
  3. 良好支持的 API。 总是有错误。 积极响应的维护人员会产生更多可用的 API
  4. 分层 API 集。 当 API 整齐地分层时,广泛的开发人员可以使用他们需要的部分,而无需引入无关的层。 作为一个优点,它迫使创建者认真思考干净和组件化的 API。

请在评论中添加更多内容。

I think the best way to answer is to list the characteristics of good web APIs instead of citing examples. If you like Twitter/Facebook/etc APIs, what aspect of these APIs do you find attractive?

I'll take a first stab:

  1. Well documented APIs, including constraints and usage policies. This enables rapid development with confidence, instead of second guessing what the parameters might mean, and what return values are.
  2. Technology/language agnostic APIs. Good APIs should be easily usable, providing the same functionality, across a wide array of languages and platforms.
  3. Well supported APIs. There are always bugs. Responsive maintainers result in more usable APIs
  4. Layered API sets. When APIs are neatly layered, a wide range of developers can consume the pieces they need without needing to pull in extraneous layers. As a plus, it forces the creators to think hard about clean and componentized APIs.

Please add more to comments.

日久见人心 2024-07-16 11:58:44

我对其他 API 没有任何经验,但即使它已经发展了多年,Facebook API 仍然很糟糕。 它远没有成为“黄金标准”。 相反,这是人们努力克服并咬紧牙关的事情,因为一旦他们最终做好了,它可以增加很多价值。

I don't have any experience with the others, but even as it has evolved over the years, the Facebook API is still awful. It doesn't come anywhere near being a "gold standard." Rather, it is something people struggle through and grit their teeth because once they finally get it right, it can add a lot of value.

↘紸啶 2024-07-16 11:58:44

一些特别好的 API:

Some APIs which are notably good:

乄_柒ぐ汐 2024-07-16 11:58:44

这将取决于您的目标受众是什么。 如果是 .net 商店,那么肥皂可能还可以,否则专注于 REST,因为它的进入门槛要低得多。
从那里查看针对您想要的相同人群的网站 API。 这样你的 api 就会感觉很熟悉。

It will depend on what your target audience is. If it is .net shops then soap is probably okay other wise focus on REST since it has a much lower bar of entry.
From there look at website APIs that target the same people you would like to. This way your api will feel familiar.

勿挽旧人 2024-07-16 11:58:44

Force(以前称为 SalesForce)API:http://www.salesforce .com/us/developer/docs/api/index.htm

Force (previously known as SalesForce) API: http://www.salesforce.com/us/developer/docs/api/index.htm

千鲤 2024-07-16 11:58:44

AtomPub 是黄金标准,因为它是由互联网上一些最聪明的人设计的。 使用 iit 作为基础不会走得太远。 这就是谷歌和微软所做的。

AtomPub is the gold standard because it was designed by some of the brightest minds on the internet. You can't go too far wrong using iit as a basis. That is what google and msft does.

铁憨憨 2024-07-16 11:58:44

有一个与此类似的问题,但没有得到太多行动,但认为链接到它会很好。

Web API 会做什么您最想复制或最受欢迎?

Had a similar question to this which didn't get much action, but thought it would be good to link to it.

What web APIs would you most want to replicate or are the most popular?

半暖夏伤 2024-07-16 11:58:44

如果我今天为现有网站设计 Web API,假设该网站在正确使用 HTTP 方面设计得很好,我会使用现有网站作为设计指南

以 Stack Overflow 为例,它已经映射了整个 URI 空间。 它具有在不同表示之间定义的完整互连集。 网站的用户已经熟悉网站结构,因此 API 结构也已经熟悉。

唯一需要更改的部分是表示的内容,以消除所有不必要的标记。 有必要添加一些额外的模板化链接,以允许当前只能通过 JavaScript 访问的搜索。 例如,通过导航不容易发现搜索用户,因为当前链接是通过 JavaScript 构建的。

真正棘手的决定是使用哪种媒体类型。 您可以使用带有 RDFa 样式元数据标记的基本 html,或者疯狂地使用 Html5 中的新 Microdata 格式。 或者,您可以返回基于 xml 或 Json 的自定义媒体类型。 像 application/vnd.stackoverflow.question+xml 之类的东西。自定义媒体类型使版本控制变得非常容易,但对于并非设计为直接访问 StackOverflow 的客户端来说不太容易访问。 自定义类型可以与 Atom feeds 结合使用,Atom feeds 大多数已经存在于 StackOverflow 中,

设计 Web API 实际上与设计网站没有什么不同,除了您提供的内容将由非 Web 浏览器的程序使用。

您不想做的是创建基于 Http 的数据访问层。 这就像向世界展示你的内衣一样。 现有网站针对所有常见使用场景进行了优化,许多 api 访问模式将是相似的,因此请重用已创建的“视图”。 可能需要在这里或那里添加一些额外的链接,以使程序更快地获取所需的数据,但这些链接可以根据需要逐步添加。

编写良好的网站对于 Web 浏览器客户端来说已经是非常有效的 API,实际上没有必要重新设计来支持任何其他类型的客户端。 API结构不需要改变,只需要改变交付的内容。

If I were designing a web api today for an existing web site, assuming the web site was well designed with respect to its proper usage of HTTP, I would use the existing web site as the design guideline.

Take Stack Overflow as an example, it has the entire URI space already mapped out. It has a complete set of interconnections defined between the different representations. Users of the site are already familiar with the site structure and therefore the API structure would already be familiar.

The only part that needs to change is the content of the representations, to eliminate all unnecessary markup. It would be necessary to add in a few extra templated links to allow for searches that are currently only accessible via javascript. For example, searching for a user is not easily discoverable via navigating because currently the link is built via javascript.

The really tricky decision is what media-type to use. You could use bare bones html with RDFa style metadata markup, or go wild and use the new Microdata format in Html5. Or, you could return a custom media type based on xml or Json. Something like application/vnd.stackoverflow.question+xml, etc. The custom media type makes versioning really easy, but it is less accessible to clients that were not designed to access StackOverflow directly. The custom types could be used in combination with Atom feeds which are mostly already there in StackOverflow,

Designing a web api is really no different than designing a website, other than the fact that you are delivering content that will be consumed by a program that is not a web browser.

What you don't want to do is create an Http based data access layer. That is just like showing your underwear to the world. The existing web site is optimized for all the common usage scenarios, many of the api access patterns are going to be similar, so reuse the "views" that have already been created. It may be necessary to add a few extra links here and there to make it a bit quicker for programs to get the data they want, but those can be added incrementally as the need arises.

Well written web sites are already very effective APIs for web browser clients, it is really not necessary to go back to the drawing board to support any other type of client. The API structure does not need to change, just the delivered content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文