Requestor is a simple HTTP library for Developers. The main idea behind this project is to make HTTP requests fun, simple and easy (Inspired by python requests).
- All the HTTP methods are supported
- Proxy Support
- Retry Support - You can set the max number of times you want to retry if the request fails
- TLS Client Certificates support
- Enable/Disable Keep-Alive
- Timeouts
- Built purely using the standard library
- more coming soon
go get github.com/flannel-dev-lab/Requestor
package main
import (
"fmt"
"github.com/flannel-dev-lab/Requestor"
"log"
)
func main() {
client := requestor.New()
headers := map[string][]string{
"Content-Type": {"application/json"},
}
queryParams := map[string][]string{
"arg1": {"test"},
}
response, err := client.Get("http://httpbin.org/get", headers, queryParams)
if err != nil {
log.Fatal(err)
}
fmt.Println("Do something with ", response)
}
The usage is similar for POST
method as well, the only difference is that you send can send data in the request.
For JSON requests, the data can be either a struct or map, by default Requestor assumes Content-Type to be application/json
For application/x-www-form-urlencoded
requests, make sure the data is in the form map[string][]string
Note: Requestor does not support XML
package main
import (
"fmt"
"github.com/flannel-dev-lab/Requestor"
"log"
)
func main() {
client := requestor.New()
headers := map[string][]string{
"Content-Type": {"application/json"},
}
queryParams := map[string][]string{
"arg1": {"test"},
}
response, err := client.Post("http://httpbin.org/get", headers, queryParams, map[string]string{"hello": "world"})
if err != nil {
log.Fatal(err)
}
fmt.Println("Do something with ", response)
}
client := requestor.New()
client.SetTimeout(10)
client := requestor.New()
client.SetHTTPProxy(proxyURL, username, password string)
or
client := requestor.New()
client.SetHTTPSProxy(proxyURL, username, password string)
client := requestor.New()
client.DisableKeepAlive(true)
Requestor loves contributions. If you find a bug, want to add a feature, you can create a PR and we will take a look.