Posts tagged rest
Peter Wiliams suggests versioning REST APIs with the Accept header. I agree that putting the version in the URI (e.g. GET /api/v1/resource) is ugly - for the Heroku client I used a custom header (X-Heroku-API-Version), which seems preferrable to me because you don’t pollute your mimetypes.
- Access response headers:
- Configurable timeout, contributed by Marc-André Cournoyer:
resource = RestClient::Resource.new 'https://example.com', :timeout => 20
- require ‘restclient’ is now the preferred notation, though require ‘rest_client’ will continue to be supported indefinitely.
Restclient 0.8 released with new features:
- The restclient binary can take get/put/post/delete as the first argument:
A few more chances for you to catch me in person:
- Silicon Valley Ruby on Rails Meetup, Sept 25 @ 7pm (this Thursday). My presentation is titled: Instant Rails Deployment to Heroku with Git. Heroku’s API and Git integration is our secret weapon, so I’m pleased to be giving a talk focused entirely on these tools.
- RubyConf 08, Nov 7 @ 1:15pm. Blake Mizerany and I will be presenting Lightweight Web Services with Sinatra and RestClient. Besides shamelessly pimping our respective open source projects, we’ll talk about why we think the future is all about small apps loosely coupled into a larger system.
I keep thinking I’ll run out of things to add to RestClient, but then I keep wanting more features. So here comes 0.7, with gzip/deflate support and client-side logs.Continue reading »
I like models. They do the heavy lifting. They’re easy to spec. You can grab them at the console or from script/runner with ease.Continue reading »
RestClient 0.6 includes an interactive shell contributed by Blake Mizerany. Lay down your
curl, for we now have a Ruby Way to fetch resources at the command line!
gem install rest-client for new features:
- SSL support
- User/password embedded in the url (e.g. https://joe:email@example.com)
- Subresource nesting with syntax (e.g.
site['posts/1/comments'].get) (more examples)
- Better exception classes with access to the response object and more readable output in irb
While we wait for web broswers to become fully REST-capable, Poster is a handy Firefox plugin for sending any type of HTTP request, including all four verbs and different content types. I usually use rest-client at a rush shell for one-offs; but if you need your browser’s cookies for a call that can’t be authenticated with http basic auth, or you just want a dialog that shows all the options visually, Poster is quite handy.
Harry Fuecks thinks MVC might be overrated. In a world of web resources, why not combine models and controllers together? Imagine replacing ActiveRecord (or my new favorite, DataMapper) with a server-side version of ActiveResource. GET, POST, PUT, and DELETE are filled in automatically, and you can extend their functionality and add suport methods.Continue reading »
When serving up an ActiveRecord as resource, you can use options like :only and :except to to_xml. But in most cases, you want the same fields served every time - on create, update, and get. So put the options into the class itself:Continue reading »
REST appealed to me right from the get-go. But it’s taken me a surprisingly long time to wrap my head around all of its implications. Some of my recent projects - building the fully RESTful Heroku API, working with Mike Clark on the Nested Resources recipe for his upcoming book, and writing rest-client - have allowed me to finally get a handle on how all the pricinples of REST fit together into a unified whole.Continue reading »
REST is part of the Ruby Way. Which is why I’m surprised that every time I go to access a RESTful resource, I find myself writing some sort of ad-hoc rest client. Net::HTTP is too low level - you’ve got to write at least three or four fairly dense lines of code even for a relatively simple GET or PUT.Continue reading »