55
66module Protocol
77 module HTTP
8- # All supported HTTP methods
8+ # All supported HTTP methods, as outlined by <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods>.
99 class Methods
10+ # The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.
1011 GET = 'GET'
12+
13+ # The HEAD method asks for a response identical to a GET request, but without the response body.
14+ HEAD = 'HEAD'
15+
16+ # The POST method submits an entity to the specified resource, often causing a change in state or side effects on the server.
1117 POST = 'POST'
18+
19+ # The PUT method replaces all current representations of the target resource with the request payload.
1220 PUT = 'PUT'
13- PATCH = 'PATCH'
21+
22+ # The DELETE method deletes the specified resource.
1423 DELETE = 'DELETE'
15- HEAD = 'HEAD'
24+
25+ # The CONNECT method establishes a tunnel to the server identified by the target resource.
26+ CONNECT = 'CONNECT'
27+
28+ # The OPTIONS method describes the communication options for the target resource.
1629 OPTIONS = 'OPTIONS'
17- LINK = 'LINK'
18- UNLINK = 'UNLINK'
30+
31+ # The TRACE method performs a message loop-back test along the path to the target resource.
1932 TRACE = 'TRACE'
20- CONNECT = 'CONNECT'
33+
34+ # The PATCH method applies partial modifications to a resource.
35+ PATCH = 'PATCH'
2136
2237 def self . valid? ( name )
2338 const_defined? ( name )
@@ -26,13 +41,18 @@ def self.valid?(name)
2641 return false
2742 end
2843
44+ # Enumerate all HTTP methods.
45+ # @yields {|name, value| ...}
46+ # @parameter name [Symbol] The name of the method, e.g. `:GET`.
47+ # @parameter value [String] The value of the method, e.g. `"GET"`.
2948 def self . each
49+ return to_enum ( :each ) unless block_given?
50+
3051 constants . each do |name |
3152 yield name , const_get ( name )
3253 end
3354 end
3455
35- # Use Methods.constants to get all constants.
3656 self . each do |name , value |
3757 define_method ( name . downcase ) do |location , headers = nil , body = nil |
3858 self . call (
0 commit comments