{"action":"created","issue":{"url":"https://api.github.com/repos/seancribbs/webmachine-ruby/issues/209","labels_url":"https://api.github.com/repos/seancribbs/webmachine-ruby/issues/209/labels{/name}","comments_url":"https://api.github.com/repos/seancribbs/webmachine-ruby/issues/209/comments","events_url":"https://api.github.com/repos/seancribbs/webmachine-ruby/issues/209/events","html_url":"https://github.com/seancribbs/webmachine-ruby/issues/209","id":53217517,"number":209,"title":"How to return 201 Created for PUT method","user":{"login":"kgish","id":79195,"avatar_url":"https://avatars.githubusercontent.com/u/79195?v=3","gravatar_id":"","url":"https://api.github.com/users/kgish","html_url":"https://github.com/kgish","followers_url":"https://api.github.com/users/kgish/followers","following_url":"https://api.github.com/users/kgish/following{/other_user}","gists_url":"https://api.github.com/users/kgish/gists{/gist_id}","starred_url":"https://api.github.com/users/kgish/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kgish/subscriptions","organizations_url":"https://api.github.com/users/kgish/orgs","repos_url":"https://api.github.com/users/kgish/repos","events_url":"https://api.github.com/users/kgish/events{/privacy}","received_events_url":"https://api.github.com/users/kgish/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-01-01T10:57:34Z","updated_at":"2015-01-01T22:34:20Z","closed_at":null,"body":"For a `PUT` request that passes an `ID` of a non-existent resource, I would like to create a new resource with that `ID` and pass back `201 Created` according to the HTTP specs.\r\n\r\nHowever, when I try the following it doesn't work. Any ideas what I am doing wrong?\r\n\r\n```ruby\r\n  def from_json\r\n    if request.method === 'PUT'\r\n      if @resource\r\n        delete_resource\r\n        response.code = 201 # <= does not work\r\n      end\r\n      attributes = params\r\n      attributes['id'] = id\r\n      new_product = Product.from_attributes(attributes)\r\n      $products << new_product\r\n      response.body = new_product.to_json\r\n    else\r\n      $products << @resource.from_json(request.body.to_s, :except => [:id])\r\n    end\r\n  end\r\n```"},"comment":{"url":"https://api.github.com/repos/seancribbs/webmachine-ruby/issues/comments/68500720","html_url":"https://github.com/seancribbs/webmachine-ruby/issues/209#issuecomment-68500720","issue_url":"https://api.github.com/repos/seancribbs/webmachine-ruby/issues/209","id":68500720,"user":{"login":"seancribbs","id":1772,"avatar_url":"https://avatars.githubusercontent.com/u/1772?v=3","gravatar_id":"","url":"https://api.github.com/users/seancribbs","html_url":"https://github.com/seancribbs","followers_url":"https://api.github.com/users/seancribbs/followers","following_url":"https://api.github.com/users/seancribbs/following{/other_user}","gists_url":"https://api.github.com/users/seancribbs/gists{/gist_id}","starred_url":"https://api.github.com/users/seancribbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/seancribbs/subscriptions","organizations_url":"https://api.github.com/users/seancribbs/orgs","repos_url":"https://api.github.com/users/seancribbs/repos","events_url":"https://api.github.com/users/seancribbs/events{/privacy}","received_events_url":"https://api.github.com/users/seancribbs/received_events","type":"User","site_admin":false},"created_at":"2015-01-01T22:34:20Z","updated_at":"2015-01-01T22:34:20Z","body":"The thing is, if the resource *did not* exist, Webmachine should be returning 201 for you, without you setting anything. This could be a bug."}}