简体   繁体   English

开始在Ruby on Rails 3应用程序中使用Web服务

[英]Getting started consuming web services in a Ruby on Rails 3 application

So I'm getting started learning Rails. 所以我开始学习Rails。 Now that Rails 3 is out, I want to stick to learning the Rails 3 way of doing things. 现在Rails 3已经出局了,我想坚持学习Rails 3的做事方式。 One of the things I want to learn how to do is how to consume web services / work with third party REST APIs / create "mashup" applications. 我想学习如何做的事情之一是如何使用第三方REST API /创建“mashup”应用程序来使用Web服务/工作。 I've only done minimal work like this with PHP and pre-built libraries. 我只用PHP和预先构建的库完成了这样的小工作。

Can someone please lead me to some resources, best practices, or give me a quick 101 lesson on how to start working with these types of APIs? 有人可以请我介绍一些资源,最佳实践,或者给我一个关于如何开始使用这些类型的API的快速课程吗? What gems should I use? 我应该使用什么宝石? Some sample code to get me started would be much appreciated. 一些示例代码让我开始将非常感激。

Update: I am specifically trying to use the Google Books API (non-authenticated). 更新:我特意尝试使用Google Books API(未经过身份验证)。 Since there is no client library for this API, I'm wondering how other Ruby/Rails developers are working with APIs that don't come with their own Ruby library. 由于此API没有客户端库,我想知道其他Ruby / Rails开发人员如何使用不带自己的Ruby库的API。 That's why I'm looking for a more generic solution to working with "fill in the blank" API. 这就是为什么我正在寻找一种更通用的解决方案来处理“填空”API。

Update: After some research, I noticed the Net::HTTP library. 更新:经过一番研究,我注意到了Net :: HTTP库。 All the tutorials that talked about it were fairly old. 所有谈到它的教程都相当陈旧。 Is this still the best library to use for consuming RESTful web services? 这仍然是用于使用RESTful Web服务的最佳库吗? Or is there a newer Gem that makes this easier? 或者是否有更新的宝石使这更容易? I just want to know which gem/library I should use, and how to work with the XML/JSON result that is returned. 我只想知道我应该使用哪个gem /库,以及如何使用返回的XML / JSON结果。

Update: This presentation was really helpful. 更新:此演示文稿非常有用。 It mentions a bunch of different libraries and shows examples of some of the libraries mentioned below: http://www.slideshare.net/pengwynn/json-and-the-apinauts 它提到了一堆不同的库,并显示了下面提到的一些库的示例: http//www.slideshare.net/pengwynn/json-and-the-apinauts

I'm a pretty big fan of HTTParty . 我是HTTParty的忠实粉丝。

It's an abstraction layer on top of Net::HTTP with a nice little DSL for consuming web services. 它是Net :: HTTP上的一个抽象层,带有一个很好的DSL用于消费Web服务。 Here's a good example of how easy it is to use. 这是一个很容易使用的好例子。

It's not without some warts (lots of dependencies) but it's really the way to go if you're on the consuming side. 这不是没有一些瑕疵(很多依赖)但如果你在消费方面,它真的是要走的路。

我推荐使用Nokogiri的REST: http: //railscasts.com/episodes/190-screen-scraping-with-nokogiri Nokogiri也适用于xml,而不仅仅是HTML。

Weary is a really neat DSL for consuming RESTful services. Weary是一款非常巧妙的DSL,用于消费RESTful服务。

Clearly inspired by HTTParty but a bit newer and a bit more concise. 显然受HTTParty的启发,但更新一点,更简洁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM