55
66module Protocol
77 module HTTP
8- # All supported HTTP methods
8+ # Provides a convenient interface for commonly supported HTTP methods.
9+ #
10+ # | Method Name | Request Body | Response Body | Safe | Idempotent | Cacheable |
11+ # | ----------- | ------------ | ------------- | ---- | ---------- | --------- |
12+ # | GET | Optional | Yes | Yes | Yes | Yes |
13+ # | HEAD | Optional | No | Yes | Yes | Yes |
14+ # | POST | Yes | Yes | No | No | Yes |
15+ # | PUT | Yes | Yes | No | Yes | No |
16+ # | DELETE | Optional | Yes | No | Yes | No |
17+ # | CONNECT | Optional | Yes | No | No | No |
18+ # | OPTIONS | Optional | Yes | Yes | Yes | No |
19+ # | TRACE | No | Yes | Yes | Yes | No |
20+ # | PATCH | Yes | Yes | No | No | No |
21+ #
22+ # These methods are defined in this module using lower case names. They are for convenience only and you should not overload those methods.
23+ #
24+ # See <https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods> for more details.
925 class Methods
26+ # The GET method requests a representation of the specified resource. Requests using GET should only retrieve data.
1027 GET = 'GET'
28+
29+ # The HEAD method asks for a response identical to a GET request, but without the response body.
30+ HEAD = 'HEAD'
31+
32+ # The POST method submits an entity to the specified resource, often causing a change in state or side effects on the server.
1133 POST = 'POST'
34+
35+ # The PUT method replaces all current representations of the target resource with the request payload.
1236 PUT = 'PUT'
13- PATCH = 'PATCH'
37+
38+ # The DELETE method deletes the specified resource.
1439 DELETE = 'DELETE'
15- HEAD = 'HEAD'
40+
41+ # The CONNECT method establishes a tunnel to the server identified by the target resource.
42+ CONNECT = 'CONNECT'
43+
44+ # The OPTIONS method describes the communication options for the target resource.
1645 OPTIONS = 'OPTIONS'
17- LINK = 'LINK'
18- UNLINK = 'UNLINK'
46+
47+ # The TRACE method performs a message loop-back test along the path to the target resource.
1948 TRACE = 'TRACE'
20- CONNECT = 'CONNECT'
49+
50+ # The PATCH method applies partial modifications to a resource.
51+ PATCH = 'PATCH'
2152
2253 def self . valid? ( name )
2354 const_defined? ( name )
@@ -26,13 +57,18 @@ def self.valid?(name)
2657 return false
2758 end
2859
60+ # Enumerate all HTTP methods.
61+ # @yields {|name, value| ...}
62+ # @parameter name [Symbol] The name of the method, e.g. `:GET`.
63+ # @parameter value [String] The value of the method, e.g. `"GET"`.
2964 def self . each
65+ return to_enum ( :each ) unless block_given?
66+
3067 constants . each do |name |
3168 yield name , const_get ( name )
3269 end
3370 end
3471
35- # Use Methods.constants to get all constants.
3672 self . each do |name , value |
3773 define_method ( name . downcase ) do |location , headers = nil , body = nil |
3874 self . call (
0 commit comments