imroc / req

Simple Go HTTP client with Black Magic
https://req.cool
MIT License
4.3k stars 350 forks source link

Tutorial ToBytes() wrong example #375

Open kostas-petrakis opened 3 months ago

kostas-petrakis commented 3 months ago

There is a small mistake in the Get Response body in the documentation.

More specific the example for the ToBytes() is:

body, err := resp.ToString()
if err != nil {
    log.Fatal(err)
}
fmt.Println("body:", body)

I think should be:

resp, err := client.R().Get(url)
if err != nil {
    log.Fatal(err)
}
body, err := resp.ToBytes()
if err != nil {
    log.Fatal(err)
}
fmt.Println("body:", string(body))
imroc commented 3 months ago

The example shows ToString() or ToBytes(), which uses ToString() for example, and ToBytes() is been omitted