Class: Protocol::HTTP::Methods

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/http/methods.rb

Overview

Provides a convenient interface for commonly supported HTTP methods.

| Method Name | Request Body | Response Body | Safe | Idempotent | Cacheable | | ———– | ———— | ————- | —- | ———- | ——— | | GET | Optional | Yes | Yes | Yes | Yes | | HEAD | Optional | No | Yes | Yes | Yes | | POST | Yes | Yes | No | No | Yes | | PUT | Yes | Yes | No | Yes | No | | DELETE | Optional | Yes | No | Yes | No | | CONNECT | Optional | Yes | No | No | No | | OPTIONS | Optional | Yes | Yes | Yes | No | | TRACE | No | Yes | Yes | Yes | No | | PATCH | Yes | Yes | No | No | No |

These methods are defined in this module using lower case names. They are for convenience only and you should not overload those methods.

See <developer.mozilla.org/en-US/docs/Web/HTTP/Methods> for more details.

Direct Known Subclasses

Middleware

Constant Summary collapse

GET =

The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.

"GET"
HEAD =

The HEAD method asks for a response identical to a GET request, but without the response body.

"HEAD"
POST =

The POST method submits an entity to the specified resource, often causing a change in state or side effects on the server.

"POST"
PUT =

The PUT method replaces all current representations of the target resource with the request payload.

"PUT"
DELETE =

The DELETE method deletes the specified resource.

"DELETE"
CONNECT =

The CONNECT method establishes a tunnel to the server identified by the target resource.

"CONNECT"
OPTIONS =

The OPTIONS method describes the communication options for the target resource.

"OPTIONS"
TRACE =

The TRACE method performs a message loop-back test along the path to the target resource.

"TRACE"
PATCH =

The PATCH method applies partial modifications to a resource.

"PATCH"

Class Method Summary collapse

Class Method Details

.eachObject

Enumerate all HTTP methods.



69
70
71
72
73
74
75
# File 'lib/protocol/http/methods.rb', line 69

def self.each
	return to_enum(:each) unless block_given?
	
	constants.each do |name|
		yield name.downcase, const_get(name)
	end
end

.valid?(name) ⇒ Boolean

Check if the given name is a valid HTTP method, according to this module.

Note that this method only knows about the methods defined in this module, however there are many other methods defined in different specifications.

Returns:

  • (Boolean)


58
59
60
61
62
63
# File 'lib/protocol/http/methods.rb', line 58

def self.valid?(name)
	const_defined?(name)
rescue NameError
	# Ruby will raise an exception if the name is not valid for a constant.
	return false
end