虽然 Rails 社区非常的成熟,但是很令人意外的是,开发 API web service 方面的资料非常之少。
Intridea 有个 Grape:https://github.com/intridea/grape 但是与 Rails 以及其他的 gem 配合度不够高。
袋鼠国的 Darcy Laycock 前几天发布了个新的 gem,RocketPants:https://github.com/filtersquad/rocket_pants 用来开发 API service,与 Rails 的配合度较高。
但是,对于简单的 API service/client架构,ActiveResource还是最方便的。
经过测试,报告给大家,可以结合 RocketPants + ActiveResource + InheritedResources (https://github.com/josevalim/inherited_resources) 一起使用,效果非常不错。
RocketPants 用来控制 API 版本,以及 JSON 的错误输出。
很好很强大。:)