HTTP client for Go
MIT License
HTTP client for Go, its also support asynchronous request
go get github.com/nahid/gohttp
POST https://httpbin.org/post
package main
import (
"github.com/nahid/gohttp"
"fmt"
)
func main() {
req := gohttp.NewRequest()
resp, err := req.
FormData(map[string]string{"name": "Nahid"}).
Post("https://httpbin.org/post")
if err != nil {
panic(err)
}
if resp.GetStatusCode() == 200 {
var resps map[string]interface{}
_ = resp.GetBodyWithUnmarshal(&resps)
fmt.Println(resps["form"])
}
}
package main
import (
"github.com/nahid/gohttp"
"fmt"
)
func main() {
req := gohttp.NewRequest()
ch := make(chan *gohttp.AsyncResponse)
var users [3]string
users[0] = "nahid"
users[1] = "shipu"
users[2] = "sujan"
for i:=0; i<len(users); i++ {
req.
FormData(map[string]string{"user": users[i]}).
AsyncPost("http://domain.app/send", ch)
}
for i:=0; i<len(users); i++ {
op := <-ch
fmt.Println(op.GetBodyAsString())
}
}
NewRequest(options ...Option)
Get(url string)
Post(url string)
Put(url string)
Patch(url string)
Delete(url string)
AsyncGet(url string, ch chan)
AsyncPost(url string, ch chan)
AsyncPut(url string, ch chan)
AsyncPatch(url string, ch chan)
AsyncDelete(url string, ch chan)
Headers(data map[string]string)
FormData(data map[string]string)
Json(data map[string]interface{})
Query(data map[string]string{})
Body(body []byte)
Text(text string)
BasicAuth(username, password string)
MultipartFormData(data map[string]string{})
Upload(name, file string)
Uploads(files map[string]string{})
UploadFromReader(param MultipartParam)
UploadsFromReader(params []MultipartParam)
GetResp()
GetStatusCode()
GetBody()
GetBodyAsByte()
GetBodyAsString()
GetBodyWithUnmarshal(v interface{})
See API doc https://godoc.org/github.com/nahid/gohttp