Created
May 12, 2014 00:11
-
-
Save stevelippert/b4ff63d932ab482ebd3d to your computer and use it in GitHub Desktop.
WeatherSTEM API Example in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "net/http" | |
| "strings" | |
| "io/ioutil" | |
| "fmt" | |
| "crypto/tls" | |
| ) | |
| func main() { | |
| tr := &http.Transport{ | |
| TLSClientConfig: &tls.Config{InsecureSkipVerify : true}, | |
| } | |
| client := &http.Client{Transport: tr} | |
| apiUrl := "https://leonschools.weatherstem.com/api" | |
| vars := (`{"api_key":"cs9ynb6t","stations":["canopyoaks"]}`) | |
| b := strings.NewReader(vars) | |
| resp, err := client.Post(apiUrl, "application/json", b) | |
| if err != nil { | |
| fmt.Println(err) | |
| } | |
| defer resp.Body.Close() | |
| body, err := ioutil.ReadAll(resp.Body) | |
| fmt.Printf("%s\n", string(body)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment