Apito REST API Integration with Golang
Perhaps one of the most important packages for any budding Go web developer is the net/http
package.
This package allows you to build HTTP servers in Go with its powerful compositional constructs.
You can also use it to make remote http calls. Follow the example below
Using net/http
library
note
Always remember to replace API_SECRET
of the Bearer Token and project-id
of the URL with the correct value from apito console.
Go to this page if you do not know where to find your api secrets and endpoints for your project
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
url := "https://api.apito.io/secured/rest/project-id"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("content-type", "application/json")
req.Header.Add("authorization", "Bearer API_SECRET")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(res)
fmt.Println(string(body))
}