简体   繁体   中英

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

So I'm getting started learning Rails. Now that Rails 3 is out, I want to stick to learning the Rails 3 way of doing things. 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. I've only done minimal work like this with PHP and pre-built libraries.

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? 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). 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. That's why I'm looking for a more generic solution to working with "fill in the blank" API.

Update: After some research, I noticed the Net::HTTP library. All the tutorials that talked about it were fairly old. Is this still the best library to use for consuming RESTful web services? 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.

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

I'm a pretty big fan of HTTParty .

It's an abstraction layer on top of Net::HTTP with a nice little DSL for consuming web services. 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.

Clearly inspired by HTTParty but a bit newer and a bit more concise.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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