|
1 | 1 | // Request examples:
|
| 2 | +// // create a simple GET request |
| 3 | +// req := GetRequest("http://www.example.com") |
2 | 4 | //
|
3 |
| -// // create a simple GET request |
4 |
| -// req := GetRequest("http://www.example.com") |
| 5 | +// // set header |
| 6 | +// req.Set("Accept", "application/json") |
5 | 7 | //
|
6 |
| -// // set header |
7 |
| -// req.Set("Accept", "application/json") |
| 8 | +// // set query parameters |
| 9 | +// req.Query("foo1", "bar1") |
| 10 | +// req.Query("foo2", "bar2") |
8 | 11 | //
|
9 |
| -// // set query parameters |
10 |
| -// req.Query("foo1", "bar1") |
11 |
| -// req.Query("foo2", "bar2") |
| 12 | +// // Build to a HTTP request |
| 13 | +// req.Build() |
12 | 14 | //
|
13 |
| -// // Build to a HTTP request |
14 |
| -// req.Build() |
| 15 | +// // method chaining is also supported |
| 16 | +// // the above is equal to: |
| 17 | +// GetRequest("http://www.example.com"). |
| 18 | +// Set("Accept", "application/json"). |
| 19 | +// Query("foo1", "bar1"). |
| 20 | +// Query("foo2", "bar2"). |
| 21 | +// Build() |
15 | 22 | //
|
16 |
| -// // method chaining is also supported |
17 |
| -// // the above is equal to: |
18 |
| -// GetRequest("http://www.example.com"). |
19 |
| -// Set("Accept", "application/json"). |
20 |
| -// Query("foo1", "bar1"). |
21 |
| -// Query("foo2", "bar2"). |
22 |
| -// Build() |
| 23 | +// // struct body |
| 24 | +// foo = Foo{Bar: "val"} |
| 25 | +// PostRequest("http://www.example.com"). |
| 26 | +// Body(foo) |
23 | 27 | //
|
24 |
| -// // struct body |
25 |
| -// foo = Foo{Bar: "val"} |
26 |
| -// PostRequest("http://www.example.com"). |
27 |
| -// Body(foo) |
| 28 | +// // String body |
| 29 | +// PostRequest("http://www.example.com"). |
| 30 | +// Body("{\"bar\": \"val\"}") |
28 | 31 | //
|
29 |
| -// // String body |
30 |
| -// PostRequest("http://www.example.com"). |
31 |
| -// Body("{\"bar\": \"val\"}") |
| 32 | +// // Stream body |
| 33 | +// PostRequest("http://www.example.com"). |
| 34 | +// Body(strings.NewReader("abcde")) |
32 | 35 | //
|
33 |
| -// // Stream body |
34 |
| -// PostRequest("http://www.example.com"). |
35 |
| -// Body(strings.NewReader("abcde")) |
36 |
| -// |
37 |
| -// // Multipart POST request |
38 |
| -// var f *os.File |
39 |
| -// PostRequest("http://www.example.com"). |
40 |
| -// Field("foo", "bar"). |
41 |
| -// File("file1", File{Name: f.Name(), Content: f}). |
42 |
| -// File("file2", File{Name: "1.txt", Content: []byte("abcde"), Type: "text/plain"}) |
| 36 | +// // Multipart POST request |
| 37 | +// var f *os.File |
| 38 | +// PostRequest("http://www.example.com"). |
| 39 | +// Field("foo", "bar"). |
| 40 | +// File("file1", File{Name: f.Name(), Content: f}). |
| 41 | +// File("file2", File{Name: "1.txt", Content: []byte("abcde"), Type: "text/plain"}) |
43 | 42 | package rest
|
44 | 43 |
|
45 | 44 | import (
|
|
0 commit comments