Skip to content

Commit 7d446cd

Browse files
committed
godoc and readme update for v0.4 release
1 parent 83dbcec commit 7d446cd

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Simple HTTP and REST client for Go inspired by Ruby rest-client. Provides notabl
2020
* Choose between HTTP and RESTful mode. Default is RESTful
2121
* `HTTP` - default upto 10 redirects and no automatic response unmarshal
2222
* `RESTful` - default no redirects and automatic response unmarshal for `JSON` & `XML`
23+
* Custom [Root Certificates](https://godoc.org/github.com/go-resty/resty#Client.SetRootCertificate) and Client [Certificates](https://godoc.org/github.com/go-resty/resty#Client.SetCertificates)
24+
* Save HTTP response into File, similar to `curl -o` flag. More info [SetOutputDirectory](https://godoc.org/github.com/go-resty/resty#Client.SetOutputDirectory) & [SetOutput](https://godoc.org/github.com/go-resty/resty#Request.SetOutput).
2325
* Client settings like `Timeout`, `RedirectPolicy`, `Proxy` and `TLSClientConfig`
2426
* Client API design
2527
* Have client level settings & options and also override at Request level if you want to
@@ -282,6 +284,25 @@ resp, err := resty.R().
282284
Post("http://myapp.com/profile")
283285
```
284286

287+
#### Save HTTP Response into File
288+
```go
289+
// Setting output directory path, If directory not exists then resty creates one!
290+
// This is optional one, if you're planning using absoule path in
291+
// `Request.SetOutput` and can used together.
292+
resty.SetOutputDirectory("/Users/jeeva/Downloads")
293+
294+
// HTTP response gets saved into file, similar to curl -o flag
295+
_, err := resty.R().
296+
SetOutput("plugin/ReplyWithHeader-v5.1-beta.zip").
297+
Get("http://bit.ly/1LouEKr")
298+
299+
// OR using absolute path
300+
// Note: output directory path is not used for absoulte path
301+
_, err := resty.R().
302+
SetOutput("/MyDownloads/plugin/ReplyWithHeader-v5.1-beta.zip").
303+
Get("http://bit.ly/1LouEKr")
304+
```
305+
285306
#### Request and Response Middleware
286307
Resty provides middleware ability to manipulate for Request and Response. It is more flexible than callback approach.
287308
```go
@@ -342,6 +363,27 @@ func (c *CustomRedirectPolicy) Apply(req *http.Request, via []*http.Request) err
342363
resty.SetRedirectPolicy(CustomRedirectPolicy{/* initialize variables */})
343364
```
344365

366+
#### Custom Root Certificates and Client Certifcates
367+
```go
368+
// Custom Root certificates, just supply .pem file.
369+
// you can add one or more root certificates, its get appended
370+
resty.SetRootCertificate("/path/to/root/pemFile1.pem")
371+
resty.SetRootCertificate("/path/to/root/pemFile2.pem")
372+
// ... and so on!
373+
374+
// Adding Client Certificates, you add one or more certificates
375+
// Sample for creating certificate object
376+
// Parsing public/private key pair from a pair of files. The files must contain PEM encoded data.
377+
cert1, err := tls.LoadX509KeyPair("certs/client.pem", "certs/client.key")
378+
if err != nil {
379+
log.Fatalf("ERROR client certificate: %s", err)
380+
}
381+
// ...
382+
383+
// You add one or more certificates
384+
resty.SetCertificates(cert1, cert2, cert3)
385+
```
386+
345387
#### Proxy Settings
346388
Default `Go` supports Proxy via environment variable `HTTP_PROXY`. Resty provides support via `SetProxy` & `RemoveProxy`.
347389
Choose as per your need.

client.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -531,8 +531,9 @@ func (c *Client) SetRootCertificate(pemFilePath string) *Client {
531531
return c
532532
}
533533

534-
// SetOutputDirectory method sets output directory. So that HTTP response gets saved underneath
535-
// output directory.
534+
// SetOutputDirectory method sets output directory for saving HTTP response into file.
535+
// If the output directory not exists then resty creates one. This setting is optional one,
536+
// if you're planning using absoule path in `Request.SetOutput` and can used together.
536537
// resty.SetOutputDirectory("/save/http/response/here")
537538
//
538539
func (c *Client) SetOutputDirectory(dirPath string) *Client {
@@ -882,7 +883,9 @@ func (r *Request) SetAuthToken(token string) *Request {
882883
}
883884

884885
// SetOutput method sets the output file for current HTTP request. Current HTTP response will be
885-
// saved into given file. It is similar to `curl -o` flag.
886+
// saved into given file. It is similar to `curl -o` flag. Absoulte path or relative path can be used.
887+
// If is it relative path then output file goes under the output directory, as mentioned
888+
// in the `Client.SetOutputDirectory`.
886889
// resty.R().
887890
// SetOutput("/Users/jeeva/Downloads/ReplyWithHeader-v5.1-beta.zip").
888891
// Get("http://bit.ly/1LouEKr")

0 commit comments

Comments
 (0)