Simplified HTTP request client in go
go get gopkg.in/ddo/request.v1
- URL
string
required - Method
string
default: "GET", anything "POST", "PUT", "DELETE" or "PATCH" - BodyStr
string
- Body
*Data
- Form
*Data
set Content-Type header as "application/x-www-form-urlencoded" - JSON
interface{}
set Content-Type header as "application/json" - Query
*Data
- Header
*Header
client := request.New()
data, res, err := client.Request(&request.Option{
URL: "https://httpbin.org/get",
})
if err != nil {
panic(err)
}
data, res, err := client.Request(&request.Option{
URL: "https://httpbin.org/post",
Method: "POST",
Body: &request.Data{
"two": []string{"2", "hai"},
"three": []string{"3", "ba", "trois"},
"email": []string{"ddo@ddo.me"},
},
})
data, res, err := client.Request(&request.Option{
URL: "https://httpbin.org/post",
Method: "POST",
Form: &request.Data{
"two": []string{"2", "hai"},
"three": []string{"3", "ba", "trois"},
"email": []string{"ddo@ddo.me"},
},
})
data, res, err := client.Request(&request.Option{
URL: "https://httpbin.org/post",
Method: "POST",
JSON: map[string]interface{}{
"int": 1,
"string": "two",
"array": []string{"3", "ba", "trois"},
"object": map[string]interface{}{
"int": 4,
},
},
})
to enable log set environment variable as
DLOG=*
or
DEBUG=* go run file.go
go test -v
- default settings
- hooks
- file