diff options
author | BurdetteLamar <burdettelamar@yahoo.com> | 2022-11-18 22:40:03 +0000 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-11-19 15:33:28 +0000 |
commit | 909ea6b60d658b2a1c4a53be81b09642dcf86d4b (patch) | |
tree | b3e167c851b91b4cef36aad0d0741358c2ec50d2 /doc/net-http | |
parent | e6162728f6ca72e97805c7ee16b98f6639b2af11 (diff) | |
download | ruby-909ea6b60d658b2a1c4a53be81b09642dcf86d4b.tar.gz |
[ruby/net-http] About the Examples moved to separate file
https://github.com/ruby/net-http/commit/0512b5bfc9
Diffstat (limited to 'doc/net-http')
-rw-r--r-- | doc/net-http/examples.rdoc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/doc/net-http/examples.rdoc b/doc/net-http/examples.rdoc new file mode 100644 index 0000000000..dd4acecda6 --- /dev/null +++ b/doc/net-http/examples.rdoc @@ -0,0 +1,30 @@ +Examples here assume that <tt>net/http</tt> has been required +(which also requires +uri+): + + require 'net/http' + +Many code examples here use these example websites: + +- https://jsonplaceholder.typicode.com. +- http://example.com. + +Some examples also assume these variables: + + uri = URI('https://jsonplaceholder.typicode.com') + uri.freeze # Examples may not modify. + hostname = uri.hostname # => "jsonplaceholder.typicode.com" + port = uri.port # => 443 + +So that example requests may be written as: + + Net::HTTP.get(uri) + Net::HTTP.get(hostname, '/index.html') + Net::HTTP.start(hostname) do |http| + http.get('/todos/1') + http.get('/todos/2') + end + +An example that needs a modified URI first duplicates +uri+, then modifies the duplicate: + + _uri = uri.dup + _uri.path = '/todos/1' |