CrudVision – Lisa Seelye

July 17, 2007

How NOT to write a HTTP socket library

Filed under: REST,actionscript,crud,work — Lisa Seelye @ 07:38

Yesterday at work we discovered that Actionscript's HTTPService library is extremely crippled in its functionality. How bad is it? Well dear reader it's common practice when writing a webserver or webservice that one should return 404 Not Found if a resource can't be found or 201 Created when a resource has been created. The other status codes also have their usefulness. In my API project for work I believe I use (only for the non-HTML access): 200, 201, 400, 401, 403, 404, 409, and 500. Quite a rich set. I also use the POST, GET, PUT, DELETE verbs.

HTTPService, however, was built in such a way that anything other than 200 OK means "Raise an exception because a fault happened" - including 201 Created (a successful response code!). HTTPService does not permit anything other than GET and POST. Good thing that Rails permits the _method hidden field, eh?

What I am most likely going to have to do is to do the same sort of thing I would have had to do if the API was done with SOAP: Always return 200 OK and maintain a set of "response objects" to cope for shortcomings in other technoloties. Instead of a standard:

RUBY:
  1. render :json => @product.to_json, :status => :created

I'll probably have to do:

RUBY:
  1. render :json => { :product => @product, :status => ErrorObject.new(201) }.to_json, :status => :o k

And I'll have to do that in every place. REST? What's that. Argh. Anyone know of a decent Actionscript HTTP library?

Powered by WordPress