Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Some simple get examples using SendGrid's REST against Github API
package main
import (
"fmt"
"encoding/json"
"github.com/sendgrid/rest"
)
func main() {
// var
url := "https://api.github.com/"
method := rest.Get
// make request and catch err
request := rest.Request{
Method: method,
BaseURL: url,
}
resp, err := rest.API(request)
if err != nil {
fmt.Println(err)
}
// Unmarshal body into body_map
body := []byte(resp.Body)
var body_iface interface{}
err = json.Unmarshal(body, &body_iface)
if err != nil {
fmt.Println(err)
}
body_map := body_iface.(map[string]interface{})
// lets select format with some output
fmt.Printf("Response: %v\n", resp.StatusCode)
fmt.Println()
fmt.Printf("Body: %v\n", body_map["current_user_url"].(string))
fmt.Println()
fmt.Printf("Headers: %v\n", resp.Headers["Status"])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.