httpclient is a thin wrapper around http.Client with some useful features.
- methods: .Post, .Get, .Put, .Delete, etc.
- simplified JSON, form and multipart requests
go get -v github.com/ninedraft/httpclient@latest
Simple POST request
resp, err := client.Post(ctx, "https://httpbin.org/post", "application/json",
strings.NewReader(`{"foo": "bar"}`))
JSON request
resp, err := client.PostJSON(ctx, "https://httpbin.org/post", map[string]string{"foo": "bar"})
Form request
resp, err := client.PostForm(ctx, "https://httpbin.org/post",
url.Values{
"foo": {"bar"}",
})
Multipart request
resp, err = client.PostMultipart(ctx, "https://httpbin.org/post",
httpclient.WriteMultiparts(
httpclient.MultipartFields(url.Values{
"foo": []string{"bar"},
}),
httpclient.MultipartFile("file", "file.txt", strings.NewReader("file content")),
))