Skip to content

Commit f57d2d1

Browse files
committed
README
1 parent 391968f commit f57d2d1

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

README.md

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
# Net::Http
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/net/http`. To experiment with that code, run `bin/console` for an interactive prompt.
3+
Net::HTTP provides a rich library which can be used to build HTTP
4+
user-agents. For more details about HTTP see
5+
[RFC2616](http://www.ietf.org/rfc/rfc2616.txt).
46

5-
TODO: Delete this and the text above, and describe your gem
7+
Net::HTTP is designed to work closely with URI. URI::HTTP#host,
8+
URI::HTTP#port and URI::HTTP#request_uri are designed to work with
9+
Net::HTTP.
10+
11+
If you are only performing a few GET requests you should try OpenURI.
612

713
## Installation
814

@@ -22,7 +28,57 @@ Or install it yourself as:
2228

2329
## Usage
2430

25-
TODO: Write usage instructions here
31+
All examples assume you have loaded Net::HTTP with:
32+
33+
```ruby
34+
require 'net/http'
35+
```
36+
37+
This will also require 'uri' so you don't need to require it separately.
38+
39+
The Net::HTTP methods in the following section do not persist
40+
connections. They are not recommended if you are performing many HTTP
41+
requests.
42+
43+
### GET
44+
45+
```ruby
46+
Net::HTTP.get('example.com', '/index.html') # => String
47+
```
48+
49+
### GET by URI
50+
51+
```ruby
52+
uri = URI('http://example.com/index.html?count=10')
53+
Net::HTTP.get(uri) # => String
54+
```
55+
56+
### GET with Dynamic Parameters
57+
58+
```ruby
59+
uri = URI('http://example.com/index.html')
60+
params = { :limit => 10, :page => 3 }
61+
uri.query = URI.encode_www_form(params)
62+
63+
res = Net::HTTP.get_response(uri)
64+
puts res.body if res.is_a?(Net::HTTPSuccess)
65+
```
66+
67+
### POST
68+
69+
```ruby
70+
uri = URI('http://www.example.com/search.cgi')
71+
res = Net::HTTP.post_form(uri, 'q' => 'ruby', 'max' => '50')
72+
puts res.body
73+
```
74+
75+
### POST with Multiple Values
76+
77+
```ruby
78+
uri = URI('http://www.example.com/search.cgi')
79+
res = Net::HTTP.post_form(uri, 'q' => ['ruby', 'perl'], 'max' => '50')
80+
puts res.body
81+
```
2682

2783
## Development
2884

@@ -32,5 +88,5 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
3288

3389
## Contributing
3490

35-
Bug reports and pull requests are welcome on GitHub at https://github.com/hsbt/net-http.
91+
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/net-http.
3692

0 commit comments

Comments
 (0)