class method
Net::HTTPSession.put
put(url, data, header = nil)
lib/net/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/net/http.rb, line 920
def HTTP.put(url, data, header = nil)
start(url.hostname, url.port,
:use_ssl => url.scheme == 'https' ) {|http|
http.put(url, data, header)
}
end
Sends a PUT request to the server; returns a Net::HTTPResponse object.
Argument url must be a URL; argument data must be a string:
Example
_uri = uri.dup _uri.path = '/posts' data = '{"title": "foo", "body": "bar", "userId": 1}' headers = {'content-type': 'application/json'} res = Net::HTTP.put(_uri, data, headers) # => #<Net::HTTPCreated 201 Created readbody=true> puts res.body
Output:
Example
{
"title": "foo",
"body": "bar",
"userId": 1,
"id": 101
}
Related:
-
Net::HTTP::Put: request class for HTTP methodPUT. -
Net::HTTP#put: convenience method for HTTP methodPUT.