我的公司正在重新设计它的 API,并希望这次一切都正确;) 这就是设置...
My company is reworking its API and wants to make everything RIGHT for this time ;) Thats the setup...
- 我们通过互联网向客户提供数据.
- 客户是手机,如 iPhone、Android、J2ME、黑莓……
- 服务器使用 Ruby on Rails 编码
我们想通过一个框架来实现...
- 在客户端上使用 ActiveResource.
- 框架应该进行模型的连接(REST)、解析和(动态)提供
- 许可证必须是开源的.
- 应包括授权.我们使用 OAuth 并且需要根据任何请求提供访问令牌.也许作为参数或在 HTTP-Header 中?
- HTTPS/SSL 支持
- 分页和关系(延迟加载)支持会很棒!否则,框架必须能够针对这些事情进行调整.
我们已经找到以下框架,请大家评估它们.也许你们中的一个人使用了其中的一些或不同的东西......
We already have found following frameworks and kindly ask you guys to evaluate them. Maybe one of you used some of them or something different...
Android:来自 Novoda/Carl-Gustaf Harroch 的 RESTProvider
- 提供者从 Android 上的数据源提供抽象,RESTProvider 自动将 RESTful API 响应解析为提供者.RESTProvider 是在 Android 中处理 Web 服务时所有常见重新实现的功能的实现.用户可以与任何提供 JSON 或 XML 作为响应的 Web 服务 API 无缝连接.要在活动中查询 RESTProvider,用户只需指定一个端点,然后查询 API 的 RESTful 功能.RESTProvider 还处理所有 HTTP 查询 &缓存.
- 除此之外没有找到太多文档
- 还提供缓存
- 计划于 2011 年初发布 + 文档
iOS:iphoneonrails/
- 用于 iOS 和 Rails 之间通信的库
- RESTful 和基于ActiveResource"的
- 包括 XML/JSON 解析器
- 免费许可
- 分页?,android?,延迟加载?
- Android:使用由 SQLLite DB 支持的游标的手工方法
- 旨在成为 Android 的高性能和最佳实践
- 使用游标
- Android:Spring Android Rest 模板模块
- Spring 的 RestTemplate 是一个强大、流行的基于 Java 的 REST 客户端.Spring Android Rest Template Module 提供了一个适用于 Android 环境的 RestTemplate 版本.
- Android:您应该随时观看 Google IO 2010 的这段视频认真考虑 REST
- Android: You always should take a look at this video of Google IO 2010 when thinking serious about REST
- Android:Feed 框架
- com.google.android.feeds
- 一组可帮助您构建内容提供程序的类.该框架专门用于帮助将您的应用连接到 Web API.
我是 RESTProvider 的作者.仍处于早期阶段,所以我不建议在生产中使用它.我一直在生产中的几个项目中使用它,但我根据特定需求调整了大部分代码.我会争取在年底之前获得一个公开的稳定 API.
I am the author of the RESTProvider. Still very early stage so I would not recommend to use it in production. I have been using it on several projects which are in production but I adapted most the code to specific needs. I will try to get a public stable API by the end of the year.
关于重新设计 API,我建议如下:
In regards to reworking the API, I would suggest the following:
- 使用 GZip 压缩
- 使用 ETag 进行缓存
- 使用无需修改的标准(我看到命名从 oauth_token 更改为 my_token 的情况,这使得大多数库无需修改即可使用)- OAuth/REST
- 对所有对象使用创建/修改时间戳和远程 ID 以启用缓存客户端(SQLite 冲突子句):{myobject":{createdAt":xxxx,rid":哈希值"}}4a.使用一个很好的方法来识别为user/activity/application返回的对象:opensocial使用应用程序id"+用户id"+活动id"
- 更喜欢 JSON 而不是 XML
- 更喜欢简单(尽可能低的深度)
- 返回具有该对象内一对多关系的完整对象:{父母":...."has": {"完整的对象不仅仅是 ID"}}
- 不要只返回 ID( "category": [ 2,3,4] 应该是 "category": [{"name": "testing", "id": 2},{"name": "生产", "id": 3 }} )
- 考虑到每个调用是相互独立的(即我应该有足够的信息来调用 test/object.json 来填充我的视图)
- Use GZip compression
- Use ETags for caching
- Use standards with no modification (I saw cases where the naming changed from oauth_token to my_token which makes most library useless without modification) - OAuth/REST
- Use creation/modified timestamp and remote ids for all objects in order to enable caching client side (SQLite conflict clauses): {"myobject": {"createdAt": xxxx, "rid": "hashvalue"}} 4a. Use a good way to identify the object returned for user/activity/application: opensocial uses "application id" + "user id" + "activity id"
- Prefer JSON over XML
- Prefer simplicity (lowest depth possible)
- Return the full object with the one to many relationship within that object: {"parent":.... "has": {"full object not just the ID"} }
- Don't return IDs only ( "category": [ 2,3,4] should be "category": [{"name": "testing", "id": 2},{"name": "production", "id": 3 }} )
- Consider each call to be independent of each other (i.e. I should have enough information for call test/object.json to populate my views)
文档:1.提供测试服务器2.提供cUrl进行测试3.在java/php/ruby等中提供示例脚本...
For documentation: 1. provide test servers 2. provide cUrl for testing 3. provide sample scripts in java/php/ruby etc...
暂时只能想到这么多.当我提出更多建议时,我可能会在此基础上添加.
That s all I can think for now. I might add ontop of this as I come with more suggestion.
更多推荐
适用于 Android、iOS 的 RESTful 框架……?
发布评论