'r' simplifies your work with the things that you usually do with requests. Things like getting the response body, headers, cookies, and even parsing Json, become simple tasks.
package main
import "github.com/AmarShaked/r"
func main() {
res, _ := r.Get('https://api.github.com/events')
res.Text()
res.Headers('content-type')
res.Cookies('key')
res.Json(&jsonValue)
}
Send a quick requests without speical settings.
res, _ := r.Get('http://httpbin.org/get')
res, _ := r.Options('http://httpbin.org/get')
res, _ := r.Head('http://httpbin.org/get')
res, _ := r.Put('http://httpbin.org/put', "Cool data")
res, _ := r.Delete('http://httpbin.org/delete', "data")
data := {"test": "shaked", "test2": "shaked2"}
res, _ := r.Post('http://httpbin.org/post', data)
To add more complex things to the request like, basic authentication, headers, and body in a lot of types, we use a advance request type.
package main
import "github.com/AmarShaked/r"
func main() {
req := r.Request{
Method: "POST",
Url: "http://httpbin.org/post",
Body: "Hello, World!",
Headers: map[string]string{"Cool-Header": "Test content"},
Auth: []string{"shaked", "pass"},
}
res, err := req.Do()
}