Simple HTTP Client for Golang
- Get/Post/Put/Head/Delete/Patch/Options
- Clean and Minimal API
- Set Request Headers
- Set URL Query Parameters
- JSON Request Body
- Creating an Instance with Default Config
Install MigMig using go get
$ go get github.com/majidsajadi/migmig
Import MigMig into your code and refer it as migmig
.
import "github.com/majidsajadi/migmig"
Simple get request
client := migmig.New()
resp, err := client.Get("https://httpbin.org/get", nil)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(body))
Simple post request with headers and JSON body
resp, err := migmig.New().Post("https://httpbin.org/post", &migmig.Config{
Headers: map[string]string{
"Content-Type": "application/json",
},
Body: map[string]interface{} {
"foo": "bar",
},
})
You can create a migmig instance with default config
client := migmig.Create(migmig.Config{
BaseURL: "https://api.github.com",
Headers: map[string]string{
"accept": "application/vnd.github.v3+json",
},
})
resp, err := client.Get("/users",
&migmig.Config{
QueryParams: map[string]string{
"per_page": "25",
"since": "300",
},
})
if err != nil {
panic(err)
}
defer resp.Body.Close()
users, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(users))
resp, err = client.Get("/users/majidsajadi/repos",
&migmig.Config{
QueryParams: map[string]string{
"per_page": "25",
},
})
if err != nil {
panic(err)
}
defer resp.Body.Close()
repos, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
fmt.Println(string(repos))
resp, err := migmig.New().Get("https://httpbin.org/get", &migmig.Config{
QueryParams: map[string]string{
"foo": "bar",
},
})
resp, err := migmig.New().Post("https://httpbin.org/post", &migmig.Config{
Headers: map[string]string {
"foo": "bar",
},
})
resp, err := migmig.New().Delete("https://httpbin.org/delete", nil)
resp, err := migmig.New().Put("https://httpbin.org/put", &migmig.Config{
Body: map[string]interface{} {
"foo": "bar",
},
})
resp, err := migmig.New().Patch("https://httpbin.org/patch", &migmig.Config{
Body: map[string]interface{} {
"foo": "bar",
},
})
Any contribution, pull requests, issue and feedbacks would be greatly appreciated. If you have any idea about the MigMig, such as, feature requests, refactoring, API changes, etc, feel free to open an issue.
MigMig is open source software licensed as MIT.