A Go HTTP Client.
Import the package.
import "github.com/sam-atkins/httpc"
headers := map[string]string{"X-Auth-Token": "topSecretToken"}
res, err := httpc.Get("https://api.com/api/v1/example/").AddHeaders(headers).Do()
type simpleJSON struct {
Data []struct {
ExampleKey string `json:"exampleKey"`
} `json:"data"`
Status string `json:"status"`
}
var sj simpleJSON
err := httpc.GetJson("https://api.com/api/v1/example/").Load(&sj)
url := "https://api.com/api/v1/example/"
type requestBody struct {
Text string
Token string
}
body := &requestBody{
Text: "this is some text",
Token: "mySecretToken",
}
res, err := httpc.Post(url, body).Do()
url := "https://api.com/api/v1/example/"
type requestBody struct {
Text string
}
body := &requestBody{
Text: "this is some text",
}
type simpleJSON struct {
Data []struct {
ExampleKey string `json:"exampleKey"`
} `json:"data"`
Status string `json:"status"`
}
var sj simpleJSON
headers := map[string]string{"X-Auth-Token": "topSecretToken"}
err := httpc.Post(url, body).AddHeaders(headers).Load(&sj)