Those 'Other' HTTP Request Methods

Posted by ryan
at 9:07 AM on Monday, March 19, 2007

With the rise of REST as a legitimate design methodology, and its first-class support in Rails, no longer are the lesser known PUT and DELETE http request methods languishing in obscurity. The awareness of REST has brought them to the forefront, completing the quad-fecta of GET, POST, PUT and DELETE.

But… there’s more. Yes, there are actually eight http request methods defined by the HTTP 1.1 spec. And why don’t we hear much of those other four request methods? Well, they’re of varying levels of usefulness to us as application developers (note that’s ‘varying’, not ‘negligible’). So here is my attempt to bring these ignored requests into the light so you can at least make your own decision as to their usefulness – and make an informed decision rather than one of ignorance.

HEAD

Think of the HEAD request method as a metadata request. You’re asking for the headers of a GET request for the same resource without getting the resource itself. This lets you see things like the size of the resource being requested, the last-modified date of the resource and any other request headers associated with the resource without actually incurring the overhead of sending the resource across the wire.

As an example, the Amazon S3 service uses a HEAD request to view information about a stored object like its size and permissions without getting the whole object. As these S3 objects represent files you can see how valuable HEAD is as you wouldn’t want to download a 1Gb file just to see the properties of that file.

OPTIONS

In the absence of human-consumable documentation, it’s tough to know what methods are supported by a particular service. For example, how do I know if I can call HEAD on a resource URI? And even in the presence of complete developer documentation, wouldn’t it be great if you could just point to a root URI and programatically interrogate the service to determine its capabilities? Yeah, that would be great and would really open up a new world of simple but semi-automated REST-based services. This is what OPTIONS attempts to do.

Unfortunately, there’s some ambiguity in the request/response spec of the OPTIONS request method. The spec itself is tight lipped about what a response looks like and even how to properly request the server capabilities. There this page-turning proposal that attempts to clear up these ambiguities, but it’s a bit outdated and I don’t know if was accepted or rejected.

This seems to be a particularly useful and important request method, I’d love to dig a little deeper into this to see how it’s being used out there in the wild. If you have any such pointers, please post them here.

TRACE

TRACE appears to be very similar to your traceroute unix command. It is “used to invoke a remote, application-layer loop back of the request message”. And how is the traveled path conveyed back to the sender? Well, the response will have a Via header value that will contain each node along the path. So instead of seeing a printout on your command line like traceroute, you can just dump the Via header contents which will look something like this (where ricky, mertz etc… are machine names):

Via: 1.0 ricky, 1.1 mertz, 1.0 lucy

It’s important to note this is not identical to traceroute in that it won’t show you the hops along the IP route, it just shows you what happens within the remote service routing.

CONNECT

CONNECT is apparently a way to request that web proxies dynamically switch to a secure IP-based connection, like an SSL tunnel. This seems particularly out of place as it operates more on the protocol level and not really on the underlying resource (as does TRACE to a certain extent). Hey, I didn’t write the thing.

Interesting huh? Yeah, didn’t think so – but it’s important to see the full picture of http and not just what web browsers or your particular application framework expose… and now you have that luxury.

tags: REST, http request methods

So You Want to Learn ActiveResource...

Posted by ryan
at 11:10 PM on Wednesday, January 17, 2007

But you can’t find much info on the subject? Stay tuned to this little teaser to learn ActiveResource in a live, real-world scenario.

Rela.tv and Gr.egario.us Taken Down

Posted by ryan
at 10:03 PM on Wednesday, January 10, 2007

As part of a larger consolidation effort I have taken down Rela.tv and gr.egario.us. They were mostly play apps for me and I’m moving on to other things. As my boss tells me, “you don’t want to dilute your brand…”

For the curious or nostalgic amongst you, you can get the source for both from my subversion repository:

Rela.tv source

svn co https://saucyworks.devguard.com/svn/projects/rela.tv/trunk rela.tv

gr.egario.us source

svn co https://saucyworks.devguard.com/svn/projects/gr.egario.us/trunk gr.egario.us

And if either of these domain names appeals to you, let me know. I’m willing to transfer them over to you if you have a project or cause that speaks to me (and even if you don’t have such a cause…)

tags: , , ,

Gr.egario.us Done Right

Posted by ryan
at 4:30 AM on Monday, November 20, 2006

I just ran across an almost exact functional clone of my RailsDay entrant, Gr.egario.us over at Quotiki. I’d say the design is much better than what I was able to do, although they don’t yet have the ability to put quotes on your own site like gr.egario.us offers.

Is that the sound of bitterness you hear? Not at all – in fact I’d love to pull gr.egario.us down at some point so please take a look at Quotiki for your future needs. My only question is – was Quotiki written in a day?

If any of the Quotiki folks want to look at how easy it is to write in Rails, let me know and I can shoot the source over to you. The only thing more satisfying than a Java-to-Rails conversion is a .NET-to-Rails conversion.

tags: , , ,

rela.tv open-sourced

Posted by ryan
at 5:25 AM on Wednesday, September 20, 2006

I gave a short and not-very-well-prepared demo of rela.tv at the Raleigh Ruby Brigade last night that generated a few inklings of interest amongst the crowd. And I use the word “interest” generously. However, I’ve been meaning to open-source the app for awhile now since I rarely find the time to play with it anymore – if for nothing else than to see if somebody else wants to use it as a learning tools as I did and try to further its functionality.

This comes with the disclaimer that I am not proud at all of the state of the code, and especially the state of the tests. Look at this as more of an opportunity for improvement than for a model by which all others should be based.

So, if you’ve got some interest in hacking away at a cool little Rails project – let me know. I’d love to see this get taken forward a few steps…

Rela.tv source access

https://saucyworks.devguard.com/svn/projects/rela.tv/trunk

Don’t know what rela.tv is? Check out the overview for a summary.

tags: , , ,

Amazon Enters the Grid-Computing Market

Posted by ryan
at 4:19 AM on Thursday, August 24, 2006

Amazon.com is quietly building an impressive stable of web services to handle every bit of your computing infrastructure. Yeah, that’s right, these aren’t tiny little consumer-oriented web services to get product information (though those exist as well). These are services to manage file storage, messaging and now computing.

Amazon’s EC2 – Elastic Cloud Service provides an on-demand computing infrastructure, accessible via an API as well as a set of command line tools. With the use of their Amazon Machine Images (AMI) you can define a set of applications and libraries that you want to make available (think of these as virtual machine images) and can start them up as needed. Amazon has a standard set of Linux-based images with MySQL, Apache etc… And to top it off you can use the S3 storage service to persist your data (subject to normal S3 fees – though the bandwidth between EC2 and S3 is free).

Pricing for EC2 is competitive, as usual – you can get the equivalent of a machine with 1.7Ghz Xeon CPU, 1.75GB of RAM, 160GB of local disk, and 250Mb/s bandwidth for $72/month. Yeah, wow.

Jesse has a nice writeup about the service and you can check out these docs to learn more as well:

Think of the possibilities – an on-demand fleet of dedicated, preconfigured Rails servers with infinite storage…

All that’s left now is for Amazon to develop a relational storage service, perhaps built on top of S3 that can provide a standard SQL interface to your data. Then you will have the complete stack of services necessary to build most any application.

tags: , , ,

Ahhhh, Typo 4 Installed

Posted by ryan
at 1:52 PM on Thursday, August 03, 2006

If you’re reading this it means that Typo 4 was successfully installed. The other clue? The generic scribbish theme that everybody in the world on Typo 4 is using. (Scribbish no more, thanks David!)

I think we need another typogarden effort, maybe typo4garden?

The typo themes viewer is helpful – but doesn’t really address version compatability.

Announcing ... rela.tv!

Posted by ryan
at 5:38 PM on Friday, July 28, 2006

I’ve been tinkering away on a little side project called rela.tv for quite awhile now. The basic concept is that it will let you visualize and organize your relationships.

“Relationships” is a loaded term, but in this case it means any relationship that can be defined in the terms of a hyperlink. With the foundation of the XFN class of relationships this can be any one of a number of pre-defined personal relationships. But rela.tv goes one step further and lets you define your own types of relationships.

It’s like tagging your links with real-world relational values.

No more explanation. Check it out and keep in mind it’s still very raw and is likely to look like poop on anything but Firefox… Hit me with any feedback you have!

tags: ,

gr.egario.us Gets an Update 5

Posted by ryan
at 4:17 AM on Friday, July 07, 2006

My RailsDay creation, gr.egario.us just got a little update. You can now set yourself up to be notified when a quote is commented on or voted on.

Right under the vote tally for a quote is the link you can use to be notified when somebody votes on that quote (when registered of course):


And right at the top of every quote’s comment thread is the same link for comment notifications:


If email notifications aren’t your thing, every listing page has it’s own rss feed – like the new quotes feed, the popular feed etc… so you can stay on top of the type of stuff that tickles your fancy.

Also new in this update is the ability to search for a quote. It currently searches on the quote body, context and who said it (no tag-based search yet). The nifty search box is brought to you by the wonder of scriptaculous’s auto-completing text fields and nice integration with Rails’ text_field_with_auto_complete javascript helper.


I’d love to hear what you think of the concept and what suggestions you have – so if you’re the opinionated type lemme have it!

tags: railsday, scriptaculous, gr.egario.us

You Can Have Your Tada List - I'll Take the Milk

Posted by ryan
at 6:32 AM on Wednesday, June 07, 2006

All you 37 Signals fan-boys can have your tada list – the truth of the matter is that Remember the Milk has it beat in every possible way. Simplicity doesn’t mean the dearth of features – it means presenting essential features in a concise and intuitive manner. Tada list simply removes features. No due dates, no priorities? – that’s not of much use to me.

tags: tadalist, rememberthemilk, todos

Migrating to Typo

Posted by ryan
at 3:28 PM on Tuesday, May 09, 2006

I’m in the middle of migrating my blog from the fine Java-based blogging app Pebble to the Rails poster-child, Typo. Just time for a change in pace, nothing against Pebble.

So, if you’re seeing this post in your reader chances are you’re also seeing duplicates. Sorry ‘bout that… This also means that I don’t think most of the comments are going to be preserved though I will try pulling over the popular posts so not all is lost.

tags: , ,

Google Calendar - Why in the world...

Posted by ryan
at 10:05 AM on Thursday, April 13, 2006

The buzz around the net today will no doubt be the release of the long-awaited and much talked about google calendar. I’ve signed up and it is pretty slick – combining a lot of the nice features of 30 Boxes, Calendar Hub and Kiko in the to-be-expected simple, usable and very web 2.0 interface. However, I have one gripe with Google Calendar (and the rest of the crowd)....

Why don’t you support tasks!!!

Tasks are part of iCal, and are an integral part of most people’s use of a calendar, yet nobody supports them. Come on people, get with the program and do it right!

And so ends my rant.

CDBaby Firefox search engine extension

Posted by ryan
at 12:04 PM on Thursday, December 08, 2005

Reading about CDBaby’s impending conversion to Rails jogged my memory of something I’ve been meaning to do for awhile, make a CDBaby Firefox search extension. So, here it is:

My CDBaby Firefox search engine extension

Whenever I hear about new music I want to try I always do a search on CDBaby.com first, then go onto more commercial ways of acquiring the music if CDBaby doesn’t have it. Hopefully this will make that process one step cleaner.

Let me know if you have comments, problems or feedback.

Making Typo properly ping Technorati (and others...)

Posted by ryan
at 12:14 PM on Monday, November 28, 2005

With the trunk version of Typo you may or may not have noticed that your Technorati (or blo.gs etc…) pings aren’t getting recognized. This is because Typo doesn’t currently send the ping in the proper format. However, I just submitted this patch to the folks at typo that should remedy things.

When you add a new entry to your blog, most blogging software supports the weblogUpdates.ping ping specification that will notify blog aggregators and other services that your blog has been updated. This is done through a pretty simple SOAP call that just tells the service the blog that was updated and the root URL of the blog.

Typo seemed to support this functionality through its “settings -> General Settings -> URLs to ping automatically” section. However it was sending a POST request with a format that wasn’t quite the weblogUpdates.ping format. (Not to mention that it wasn’t a SOAP request). I noticed this and submitted this issue to the Typo guys. After sitting back and basking in my find for a day or two it dawned on me that I had every ability to fix the issue. So after toiling a bit and making a few passes, I did just that and submitted the above mentioned patch.

So why do I mention this? Because I’m egotistical and self-centered? Well, yes. But also because this announcement by scott made me a bit nervous that it might be awhile until the patch made it into the trunk and I thought a few people might want to get their posts recognized sooner by the very important ecosystem of blog aggregators and services. No knock on the Typo guys at all, just an opportunity to get the functionality in place sooner rather than later.

If you’re not up to doing the whole patch application process yourself, you can download these three files into your current Typo installation. (Make sure you’re on the most recent revision, though – 760 as of this writing)

app/models/ping.rb
app/controllers/application.rb
app/controllers/admin/content_controller.rb

Also let me know if you see a better way of doing things as I’m no Rails pro.

Creating weblogUpdates.ping SOAP web services with Rails

Posted by ryan
at 10:39 AM on Tuesday, November 22, 2005

I’ve recently had the occasion to work on both the client and server ends of implementing the weblogUpdates.ping SOAP call and thought it might be worthwhile to post the results here.

First, a little background. “weblogUpdates.ping” is a way for blogging software to notify aggregators that there’s been an update to the blog. If you use Technorati or blo.gs this is how your blogging package notifies the services when you post a new entry. The specification for this SOAP call is outlined here and here.

As you can see, it’s a pretty simple call. We need to make a SOAP call to the “weblogUpdates.ping” method with two string arguments, the title of the blog and the absolute URL of the blog – not the permalink of the new entry. (taken from technorati docs)

<?xml version="1.0"?>
<methodCall>
  <methodName>weblogUpdates.ping</methodName>
  <params>
    <param>
      <value>YOUR WEBLOG NAME HERE</value>
    </param>
    <param>
      <value>http://www.YOURWEBLOGURL.com/</value>
    </param>
  </params>
</methodCall>
So, on to implementing both sides of this in Ruby on Rails...

Let’s start with the client side, if you have a Rails app (such as a Rails blogger like Typo) that needs to send out a ping to Technorati or any other blog aggregator then you’ll need to send out this ping. This turns out to be quite simple, here’s the jist of the code (derived from Why’s example)

begin

  server = XMLRPC::Client.new2(URI.parse(endpoint_url).to_s)

  begin
    result = server.call("weblogUpdates.ping", blog_name,
                          blog_url)
  rescue XMLRPC::FaultException => e
    logger.error(e)
  end

rescue Exception => e
  logger.error(e)
end
Keep in mind this is a synchronous call – so if the aggregator is slow in responding it will hang your app. Some thought should be given to spawning the actual call in a new thread.

So what about when you’re writing a Rails app that serves as an aggregator that needs to receive these ping calls? It’s not as simple as sending the ping, but with Rails’ strong web services support it’s still quite easy. So here’s how you go about doing that:

  • Create the API class that defines what the call looks like:
    # In app/apis/blog_api.rb
    
    class BlogAPI < ActionWebService::API::Base
      inflect_names false
      api_method :ping,
                 :expects => [ {:name => :string}, {:url => :string} ]
    end
    
    Note that you have to set the “inflect_names” property to false since not doing so will cause the underlying SOAP method to be named “weblogUpdates.Ping”, which we don’t want. Also notice that we haven’t specified the full name of the call and have left off the “weblogUpdates” prefix. We’ll resolve this a few steps down by using the layered dispatching mode of Rails’ web services support which will bind a web service class to a specific name.
  • Next let’s create the actual web service class:
    # app/models/blog_api_service.rb
    
    class BlogAPIService < ActionWebService::Base
    
      web_service_api BlogAPI
    
      def ping(name, url)
        #Put your business logic here that handles incoming pings
      end
    end
    
    Pretty simple again, define a ping method that matches the BlogAPI method defined in the first step and add your business logic.
  • Now let’s wrap it all up with the controller that will handle the actual result:
    # app/controllers/blog_controller.rb
    
    class BlogController < ApplicationController
    
      web_service_scaffold :invoke
      web_service_dispatching_mode :layered
      web_service :weblogUpdates, BlogAPIService.new
    
    end
    
  • Now your SOAP weblogUpdates.ping service will be waiting at http://yourhostname/blog/api. To test it you can go to: http://yourhostname/blog/invoke.

And there you have it, sending and receiving the SOAP weblogUpdates.ping call. You can now write your own Rails version of Technorati and Moveable Type, so have at it.