Thanks for the links and book recommendation.
In rails 2.0, am I right in thinking the following?
- ActiveResource is used to connect an application to an excising REST
web service. (eg. I would use ActiveResource to connect my app to the
twitter web service)
When you use Rails’ conventions, ActiveResource will just work out of the box and it makes inter-Rails app communication a breeze. Rails is all about convention over configuration and ActiveResource fits in the motto perfectly. If you want to use it with some other framework, you’ll have to make sure you implement the Rails conventions in that framework too.
Given that Twitter is a Rails app, it could well be that it’s possible to integrate your Rails app with it using ActiveResource. I don’t know what API they use.
You could also do some transformations on a non-ActiveResource webservice to convert its way of speaking into the ActiveResource way. The Rails Way website has a blog post on this:
- ActionWebServices should no longer be used in Rails 2.0.
ActiveResource (so a RESTful API) is the preferred way of doing things in Rails 2. You can still use the old webservices classes, but it’s a seperate plugin. Nobody says you can’t use them anymore, they’re just not part of the core framework anymore.
Finally (please correct me if I am wrong), Everything I need to allow
people to connect to my app is already within the controllers respond_to
block, and all I need to do is add .xml on to the end of everything or
make a subdomain e.g. (api.mydomain.com) use the xml format?
One final question, providing all the above is correct?
What is the best way to restrict use of the xml format by using an API
Why can’t you use http authentication? That’s kind of the Rails convention for authenticating, and that’s also how it’s implemented in the restful_authentication plugin.
If you really want to use the api key method, when a user requests and account, generate some hash and put it in a db field, then use that in your authentication method when the format requested is xml.
respond_to do |format|
Peter De Berdt