seancribbs/webmachine-ruby — pull request #26 by 1000jobboersen (2012-01-12 14:22:55+00:00)
Title: Resource#create_path is optional if Location is set

Consider this a proposal --

This introduces a slight change to the semantics in the processing of a
request when `#post_is_create?` returns true, adding support for
environments where `create_path` cannot be determined before processing
the request.

Thus, an implementor using MongoDB can do:

class MyResource
def create_path
request.path_info[:id] = BSON::ObjectId.new
"/resources/#{request.path_info[:id]}"
end
end

While an implementor using Postgres might do:

class MyResource
def create_path() nil end
def accept_json
resource = Resource.create
response.headers['Location'] = "/resources/#{resource.id}"
true
end
end

Additionally, the response header's location is only set after the
accept handler has run, in case the handler fails for some other reason
(such as an incorrect content type).

With this feature and the feature guard feature #25, I'm able to get the following (very pleasing!) behavior: https://gist.github.com/1600780