Method: Gem::Net::HTTP#patch
- Defined in:
- lib/rubygems/vendor/net-http/lib/net/http.rb
#patch(path, data, initheader = nil, dest = nil, &block) ⇒ Object
:call-seq:
patch(path, data, initheader = nil) {|res| ... }
Sends a PATCH request to the server; returns an instance of a subclass of Gem::Net::HTTPResponse.
The request is based on the Gem::Net::HTTP::Patch object created from string path
, string data
, and initial headers hash initheader
.
With a block given, calls the block with the response body:
data = '{"userId": 1, "id": 1, "title": "delectus aut autem", "completed": false}'
http = Gem::Net::HTTP.new(hostname)
http.patch('/todos/1', data) do |res|
p res
end # => #<Gem::Net::HTTPOK 200 OK readbody=true>
Output:
"{\n \"userId\": 1,\n \"id\": 1,\n \"title\": \"delectus aut autem\",\n \"completed\": false,\n \"{\\\"userId\\\": 1, \\\"id\\\": 1, \\\"title\\\": \\\"delectus aut autem\\\", \\\"completed\\\": false}\": \"\"\n}"
With no block given, simply returns the response object:
http.patch('/todos/1', data) # => #<Gem::Net::HTTPCreated 201 Created readbody=true>
2074 2075 2076 |
# File 'lib/rubygems/vendor/net-http/lib/net/http.rb', line 2074 def patch(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+ send_entity(path, data, initheader, dest, Patch, &block) end |