/httpc

Golang HTTP Client

Primary LanguageGoMIT LicenseMIT

CI

httpc

A Go HTTP Client.

Usage

Import the package.

import "github.com/sam-atkins/httpc"

Example GET requests

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)

Example POST requests

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)