sinatra rest-client etag -


my goal address "lost update problem" (see http://www.w3.org/1999/04/editing/) in put operations. using sinatra, , client use rest_client. how can check if works? client return 200 code. using arguments of calling correctly? (put works)

sinatra code:

put '/players/:id' |id|     etag 'something'     if player[id].nil?         halt 404     end     begin         data = json.parse(params[:data])         pl = player[id]         pl.name = data['name']         pl.position = data['position']         if pl.save             "resource modified."         else             status 412             redirect '/players'            end      rescue sequel::databaseerror            409 #conflict - request unsuccessful due conflict in state of resource.     rescue exception => e          400         puts e.message        end end 

client invocation:

player = {"name" => "john smith", "position" => "def"}.to_json  restclient.put('http://localhost:4567/players/1', {:data => player, :content_type => :json, :if_none_match => '"something"'}){ |response, request, result, &block|     p response.code.to_s + " " + response } 

i tried put :if_none_match => "something", tried :if_match. nothing changes. how can put headers restclient request? how obtain sth different 200 status? (ie 304 not modified)?

your payload , headers in same hash. have specify headers restclient in second hash. try:

player = {"name" => "john smith", "position" => "def"}.to_json headers = {:content_type => :json, :if_none_match => '"something"'}  restclient.put('http://localhost:4567/players/1', {:data => player}, headers) |response, request, result, &block|     p response.code.to_s + " " + response end 

i not sure if restclient translates headers correctly. if above doesn't work, try with:

headers = {'content-type' => :json, 'if-none-match' => '"something"'} 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -