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.
- Make http requests from Golang
- Intercept request and response
- Transform request and response data
go mod:
go get github.com/monaco-io/request
- OPTIONS
- GET
- HEAD
- POST
- PUT
- DELETE
- TRACE
- CONNECT
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
client := request.Client{
URL: "https://google.com",
Method: "GET",
Params: map[string]string{"hello": "world"},
}
resp, err := client.Do()
log.Println(string(resp), err)
}
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
client := request.Client{
URL: "https://google.com",
Method: "POST",
Params: map[string]string{"hello": "world"},
Body: []byte(`{"hello": "world"}`),
}
resp, err := client.Do()
log.Println(string(resp), err)
}
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
client := request.Client{
URL: "https://google.com",
Method: "POST",
ContentType: request.ApplicationXWwwFormURLEncoded, // default is "application/json"
}
resp, err := client.Do()
log.Println(string(resp), err)
}
package main
import (
"log"
"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",
}, // xxx:xxx
}
resp, err := client.Do()
log.Println(string(resp), err)
}
package main
import (
"log"
"github.com/monaco-io/request"
)
func main() {
client := request.Client{
URL: "https://google.com",
Method: "POST",
Timeout: 10, // seconds
}
resp, err := client.Do()
log.Println(string(resp), err)
}