|
2 | 2 |
|
3 | 3 | Simple HTTP and REST client for Go inspired by Ruby rest-client. Provides notable features - robust request body input, auto marshal & unmarshal, request and response middlewares, custom & extensible redirect policy (multiple policies can be applied), etc.
|
4 | 4 |
|
| 5 | +***Latest v0.5 released on Jan 03, 2016.*** |
| 6 | + |
5 | 7 | #### Features
|
6 | 8 | * Get, Post, Put, Delete, Head, Patch and Options
|
7 | 9 | * Simple methods/chainable methods for settings and request
|
8 | 10 | * Request Body can be `string`, `[]byte`, `struct` and `map`
|
9 | 11 | * Auto detect `Content-Type`
|
10 | 12 | * Response object gives you more possibility
|
11 |
| - * Access as `[]byte` array - `response.Body` OR Access as `string` - `response.String()` |
12 |
| - * Know your `response.Time()` and when we `response.ReceivedAt` |
| 13 | + * Access as `[]byte` array - `response.Body()` OR Access as `string` - `response.String()` |
| 14 | + * Know your `response.Time()` and when we `response.ReceivedAt()` |
13 | 15 | * Have a look [godoc](https://godoc.org/github.com/go-resty/resty#Response)
|
14 | 16 | * Automatic marshal and unmarshal for `JSON` and `XML` content type
|
15 | 17 | * Default is `JSON`, if you supply `struct/map` without header `Content-Type`
|
@@ -44,7 +46,7 @@ resty tested with Go v1.2 and above.
|
44 | 46 | * etc.
|
45 | 47 |
|
46 | 48 | ## Installation
|
47 |
| -#### Stable |
| 49 | +#### Stable - Versioning |
48 | 50 | ```sh
|
49 | 51 | go get gopkg.in/resty.v0
|
50 | 52 | ```
|
@@ -72,7 +74,7 @@ fmt.Printf("\nResponse Status Code: %v", resp.StatusCode())
|
72 | 74 | fmt.Printf("\nResponse Status: %v", resp.Status())
|
73 | 75 | fmt.Printf("\nResponse Time: %v", resp.Time())
|
74 | 76 | fmt.Printf("\nResponse Recevied At: %v", resp.ReceivedAt())
|
75 |
| -fmt.Printf("\nResponse Body: %v", resp) |
| 77 | +fmt.Printf("\nResponse Body: %v", resp) // or string(resp.Body()) |
76 | 78 | // more...
|
77 | 79 |
|
78 | 80 | /* Output
|
@@ -384,24 +386,33 @@ if err != nil {
|
384 | 386 | resty.SetCertificates(cert1, cert2, cert3)
|
385 | 387 | ```
|
386 | 388 |
|
387 |
| -#### Proxy Settings |
| 389 | +#### Proxy Settings - Client as well as at Request Level |
388 | 390 | Default `Go` supports Proxy via environment variable `HTTP_PROXY`. Resty provides support via `SetProxy` & `RemoveProxy`.
|
389 | 391 | Choose as per your need.
|
| 392 | + |
| 393 | +**Client Level Proxy** settings applied to all the request |
390 | 394 | ```go
|
391 | 395 | // Setting a Proxy URL and Port
|
392 | 396 | resty.SetProxy("http://proxyserver:8888")
|
393 | 397 |
|
394 | 398 | // Want to remove proxy setting
|
395 | 399 | resty.RemoveProxy()
|
396 | 400 | ```
|
| 401 | +**Request Level Proxy** settings, gives control to override at individal request level |
| 402 | +```go |
| 403 | +// Set proxy for current request |
| 404 | +resp, err := c.R(). |
| 405 | + SetProxy("http://sampleproxy:8888"). |
| 406 | + Get("http://httpbin.org/get") |
| 407 | +``` |
397 | 408 |
|
398 | 409 | #### Choose REST or HTTP mode
|
399 | 410 | ```go
|
| 411 | +// REST mode. This is Default. |
| 412 | +resty.SetRESTMode() |
| 413 | + |
400 | 414 | // HTTP mode
|
401 | 415 | resty.SetHTTPMode()
|
402 |
| - |
403 |
| -// REST mode. Default one |
404 |
| -resty.SetRESTMode() |
405 | 416 | ```
|
406 | 417 |
|
407 | 418 | #### Wanna Multiple Clients
|
|
0 commit comments