Results for: "to_proc"

No documentation available

This class is the base class for Net::HTTP request classes. The class should not be used directly; instead you should use its subclasses, listed below.

Creating a Request

An request object may be created with either a URI or a string hostname:

require 'net/http'
uri = URI('https://jsonplaceholder.typicode.com/')
req = Net::HTTP::Get.new(uri)          # => #<Net::HTTP::Get GET>
req = Net::HTTP::Get.new(uri.hostname) # => #<Net::HTTP::Get GET>

And with any of the subclasses:

req = Net::HTTP::Head.new(uri) # => #<Net::HTTP::Head HEAD>
req = Net::HTTP::Post.new(uri) # => #<Net::HTTP::Post POST>
req = Net::HTTP::Put.new(uri)  # => #<Net::HTTP::Put PUT>
# ...

The new instance is suitable for use as the argument to Net::HTTP#request.

Request Headers

A new request object has these header fields by default:

req.to_hash
# =>
{"accept-encoding"=>["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],
"accept"=>["*/*"],
"user-agent"=>["Ruby"],
"host"=>["jsonplaceholder.typicode.com"]}

See:

You can add headers or override default headers:

#   res = Net::HTTP::Get.new(uri, {'foo' => '0', 'bar' => '1'})

This class (and therefore its subclasses) also includes (indirectly) module Net::HTTPHeader, which gives access to its methods for setting headers.

Request Subclasses

Subclasses for HTTP requests:

Subclasses for WebDAV requests:

This class is the base class for Net::HTTP response classes.

About the Examples

Returned Responses

Method Net::HTTP.get_response returns an instance of one of the subclasses of Net::HTTPResponse:

Net::HTTP.get_response(uri)
# => #<Net::HTTPOK 200 OK readbody=true>
Net::HTTP.get_response(hostname, '/nosuch')
# => #<Net::HTTPNotFound 404 Not Found readbody=true>

As does method Net::HTTP#request:

req = Net::HTTP::Get.new(uri)
Net::HTTP.start(hostname) do |http|
  http.request(req)
end # => #<Net::HTTPOK 200 OK readbody=true>

Class Net::HTTPResponse includes module Net::HTTPHeader, which provides access to response header values via (among others):

Examples:

res = Net::HTTP.get_response(uri) # => #<Net::HTTPOK 200 OK readbody=true>
res['Content-Type']               # => "text/html; charset=UTF-8"
res.content_type                  # => "text/html"

Response Subclasses

Class Net::HTTPResponse has a subclass for each HTTP status code. You can look up the response class for a given code:

Net::HTTPResponse::CODE_TO_OBJ['200'] # => Net::HTTPOK
Net::HTTPResponse::CODE_TO_OBJ['400'] # => Net::HTTPBadRequest
Net::HTTPResponse::CODE_TO_OBJ['404'] # => Net::HTTPNotFound

And you can retrieve the status code for a response object:

Net::HTTP.get_response(uri).code                 # => "200"
Net::HTTP.get_response(hostname, '/nosuch').code # => "404"

The response subclasses (indentation shows class hierarchy):

There is also the Net::HTTPBadResponse exception which is raised when there is a protocol error.

Parent class for redirection (3xx) HTTP response classes.

A redirection response indicates the client must take additional action to complete the request.

References:

Parent class for client error (4xx) HTTP response classes.

A client error response indicates that the client may have caused an error.

References:

Parent class for server error (5xx) HTTP response classes.

A server error response indicates that the server failed to fulfill a request.

References:

Response class for No Content responses (status code 204).

The No Content response indicates that the server successfully processed the request, and is not returning any content.

References:

Response class for Reset Content responses (status code 205).

The Reset Content response indicates that the server successfully processed the request, asks that the client reset its document view, and is not returning any content.

References:

Response class for Request Timeout responses (status code 408).

The server timed out waiting for the request.

References:

Response class for Request Timeout responses (status code 408).

The server timed out waiting for the request.

References:

Response class for Precondition Failed responses (status code 412).

The server does not meet one of the preconditions specified in the request headers.

References:

Response class for Range Not Satisfiable responses (status code 416).

The request entity has a media type which the server or resource does not support.

References:

Response class for Range Not Satisfiable responses (status code 416).

The request entity has a media type which the server or resource does not support.

References:

Response class for Locked (WebDAV) responses (status code 423).

The requested resource is locked.

References:

Response class for Precondition Required responses (status code 428).

The origin server requires the request to be conditional.

References:

Response class for Internal Server Error responses (status code 500).

An unexpected condition was encountered and no more specific message is suitable.

References:

No documentation available

Raised on redirection, only occurs when redirect option for HTTP is false.

Base class of exceptions from OptionParser.

Represents a hash key/value pair.

{ a => b }
  ^^^^^^

Represents a splat in a hash literal.

{ **foo }
  ^^^^^

Represents block method arguments.

bar(&args)
^^^^^^^^^^

Represents a block of ruby code.

[1, 2, 3].each { |i| puts x }

^^^^^^^^^^^^^^

Represents a block parameter to a method, block, or lambda definition.

def a(&b)
      ^^
end

Represents a block’s parameters declaration.

-> (a, b = 1; local) { }
   ^^^^^^^^^^^^^^^^^

foo do |a, b = 1; local|
       ^^^^^^^^^^^^^^^^^
end
Search took: 6ms  ·  Total Results: 1894