Request
HTTP client for golang, Inspired by Javascript-axios Python-request. If you have experience about axios or requests, you will love it. No 3rd dependency.
Features
- Make http requests from Golang
- Transform request and response data
Installing
go mod:
go get github.com/monaco-io/request
Methods
- OPTIONS
- GET
- HEAD
- POST
- PUT
- DELETE
- TRACE
- CONNECT
Example
POST
package main
import (
"github.com/monaco-io/request"
)
func main() {
client := request.Client{
URL: "https://google.com",
Method: "POST",
Query: map[string]string{"hello": "world"},
JSON: []byte(`{"hello": "world"}`),
}
var result interface{}
resp := client.Send()
err := resp.Scan(&result).Error()
str := resp.String()
bytes := resp.Bytes()
...
POST with empty request
package main
import (
"github.com/monaco-io/request"
)
func main() {
var data interface{}
resp := request.
New().
POST("http://httpbin.org/post").
AddHeader(map[string]string{"Google": "google"}).
AddBasicAuth("google", "google").
AddURLEncodedForm(map[string]string{"data": "google"}).
Send().
Scan(&data)
...
Authorization
package main
import (
"github.com/monaco-io/request"
)
func main() {
client := request.Client{
URL: "https://google.com",
Method: "POST",
BasicAuth: request.BasicAuth{
Username:"user_xxx",
Password:"pwd_xxx",
},
}
}
Timeout
package main
import (
"github.com/monaco-io/request"
)
func main() {
client := request.Client{
URL: "https://google.com",
Method: "POST",
Timeout: time.Second*10,
}
}
Cookies
package main
import (
"github.com/monaco-io/request"
)
func main() {
client := request.Client{
URL: "https://google.com",
CookiesMap: map[string]string{
"cookie_name": "cookie_value",
}
}
}
TLS
package main
import (
"github.com/monaco-io/request"
)
func main() {
client := request.Client{
URL: "https://google.com",
TLSConfig: &tls.Config{InsecureSkipVerify: true},
}
}