Skip to content

Commit bb0d078

Browse files
[DOC] Clarify strategies (#106)
1 parent 3308362 commit bb0d078

File tree

1 file changed

+52
-57
lines changed

1 file changed

+52
-57
lines changed

lib/net/http.rb

Lines changed: 52 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -34,67 +34,62 @@ class HTTPHeaderSyntaxError < StandardError; end
3434

3535
# \Class \Net::HTTP provides a rich library that implements the client
3636
# in a client-server model that uses the \HTTP request-response protocol.
37-
# For information about \HTTP, see
37+
# For information about \HTTP, see:
3838
#
3939
# - {Hypertext Transfer Protocol}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol].
4040
# - {Technical overview}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Technical_overview].
4141
#
42-
# Note: If you are performing only a few GET requests, consider using
43-
# {OpenURI}[https://docs.ruby-lang.org/en/master/OpenURI.html];
44-
# otherwise, read on.
45-
#
46-
# == Synopsis
47-
#
48-
# If you are already familiar with \HTTP, this synopsis may be helpful.
49-
#
50-
# {Session}[rdoc-ref:Net::HTTP@Sessions] with multiple requests for
51-
# {HTTP methods}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods]:
52-
#
53-
# Net::HTTP.start(hostname) do |http|
54-
# # Session started automatically before block execution.
55-
# http.get(path_or_uri, headers = {})
56-
# http.head(path_or_uri, headers = {})
57-
# http.post(path_or_uri, data, headers = {}) # Can also have a block.
58-
# http.put(path_or_uri, data, headers = {})
59-
# http.delete(path_or_uri, headers = {Depth: 'Infinity'})
60-
# http.options(path_or_uri, headers = {})
61-
# http.trace(path_or_uri, headers = {})
62-
# http.patch(path_or_uri, data, headers = {}) # Can also have a block.
63-
# # Session finished automatically at block exit.
64-
# end
65-
#
66-
# {Session}[rdoc-ref:Net::HTTP@Sessions] with multiple requests for
67-
# {WebDAV methods}[https://en.wikipedia.org/wiki/WebDAV#Implementation]:
68-
#
69-
# Net::HTTP.start(hostname) do |http|
70-
# # Session started automatically before block execution.
71-
# http.copy(path_or_uri, headers = {})
72-
# http.lock(path_or_uri, body, headers = {})
73-
# http.mkcol(path_or_uri, body = nil, headers = {})
74-
# http.move(path_or_uri, headers = {})
75-
# http.propfind(path_or_uri, body = nil, headers = {'Depth' => '0'})
76-
# http.proppatch(path_or_uri, body, headers = {})
77-
# http.unlock(path_or_uri, body, headers = {})
78-
# # Session finished automatically at block exit.
79-
# end
80-
#
81-
# Each of the following methods automatically starts and finishes
82-
# a {session}[rdoc-ref:Net::HTTP@Sessions] that sends a single request:
83-
#
84-
# # Return string response body.
85-
# Net::HTTP.get(hostname, path, port = 80)
86-
# Net::HTTP.get(uri, headers = {}, port = 80)
87-
#
88-
# # Write string response body to $stdout.
89-
# Net::HTTP.get_print(hostname, path_or_uri, port = 80)
90-
# Net::HTTP.get_print(uri, headers = {}, port = 80)
91-
#
92-
# # Return response as Net::HTTPResponse object.
93-
# Net::HTTP.get_response(hostname, path_or_uri, port = 80)
94-
# Net::HTTP.get_response(uri, headers = {}, port = 80)
42+
# == Strategies
43+
#
44+
# - If you will make only a few GET requests,
45+
# consider using {OpenURI}[https://docs.ruby-lang.org/en/master/OpenURI.html].
46+
# - If you will make only a few requests of all kinds,
47+
# consider using the various singleton convenience methods in this class.
48+
# Each of the following methods automatically starts and finishes
49+
# a {session}[rdoc-ref:Net::HTTP@Sessions] that sends a single request:
50+
#
51+
# # Return string response body.
52+
# Net::HTTP.get(hostname, path, port = 80)
53+
# Net::HTTP.get(uri, headers = {}, port = 80)
54+
#
55+
# # Write string response body to $stdout.
56+
# Net::HTTP.get_print(hostname, path_or_uri, port = 80)
57+
# Net::HTTP.get_print(uri, headers = {}, port = 80)
58+
#
59+
# # Return response as Net::HTTPResponse object.
60+
# Net::HTTP.get_response(hostname, path_or_uri, port = 80)
61+
# Net::HTTP.get_response(uri, headers = {}, port = 80)
62+
# Net::HTTP.post(uri, data, headers = {})
63+
# Net::HTTP.post_form(uri, params)
64+
#
65+
# - If performance is important, consider using sessions, which lower request overhead.
66+
# This {session}[rdoc-ref:Net::HTTP@Sessions] has multiple requests for
67+
# {HTTP methods}[https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods]
68+
# and {WebDAV methods}[https://en.wikipedia.org/wiki/WebDAV#Implementation]:
69+
#
70+
# Net::HTTP.start(hostname) do |http|
71+
# # Session started automatically before block execution.
72+
# http.get(path_or_uri, headers = {})
73+
# http.head(path_or_uri, headers = {})
74+
# http.post(path_or_uri, body, headers = {}) # Can also have a block.
75+
# http.put(path_or_uri, body, headers = {})
76+
# http.delete(path_or_uri, headers = {Depth: 'Infinity'})
77+
# http.options(path_or_uri, headers = {})
78+
# http.trace(path_or_uri, headers = {})
79+
# http.patch(path_or_uri, body, headers = {}) # Can also have a block.
80+
# http.copy(path_or_uri, headers = {})
81+
# http.lock(path_or_uri, body, headers = {})
82+
# http.mkcol(path_or_uri, body = nil, headers = {})
83+
# http.move(path_or_uri, headers = {})
84+
# http.propfind(path_or_uri, body = nil, headers = {'Depth' => '0'})
85+
# http.proppatch(path_or_uri, body, headers = {})
86+
# http.unlock(path_or_uri, body, headers = {})
87+
# # Session finished automatically at block exit.
88+
# end
9589
#
96-
# Net::HTTP.post(uri, data, headers = {})
97-
# Net::HTTP.post_form(uri, params)
90+
# The methods cited above are convenience methods that, via their few arguments,
91+
# allow minimal control over the requests.
92+
# For greater control, consider using {request objects}[rdoc-ref:Net::HTTPRequest].
9893
#
9994
# == About the Examples
10095
#
@@ -183,7 +178,7 @@ class HTTPHeaderSyntaxError < StandardError; end
183178
# - May contain any number of requests.
184179
# - Is ended by instance method Net::HTTP#finish.
185180
#
186-
# See example sessions at the {Synopsis}[rdoc-ref:Net::HTTP@Synopsis].
181+
# See example sessions at {Strategies}[rdoc-ref:Net::HTTP@Strategies].
187182
#
188183
# === Session Using \Net::HTTP.start
189184
#

0 commit comments

Comments
 (0)