Yes - in AppGameKit tier 1 the HTTP commands will provide you with all you need to communicate with a RESTful API over the interwebs. Very easy to use. Here's an example of some code of mine to get a hash from my server:
function downloadHash(in as string)
query as string
out as string
query = "getHash?catID=" + in
if state.mock
out = getFromMock(query)
else
out = getFromServer(query)
endif
endFunction out
function getFromServer(q as string)
response as string
http = CreateHTTPConnection()
SetHTTPHost(http, ip.api, ip.tls)
SetHTTPTimeout(http, 5000)
SendHTTPRequestASync(http, q)
while GetHTTPResponseReady(http) = 0
print("Connecting...")
sync()
endWhile
if GetHTTPResponseReady(http) = -1
print("Connection failed!")
state.httpOK = false
response = ""
else
response = GetHTTPResponse(http)
state.httpOK = true
endif
CloseHTTPConnection(http)
DeleteHTTPConnection(http)
endFunction response
Though mind you, there is quite a lot going on in there to keep track of potential errors and forward status, plus ofcourse storing the server address in a datastructure which is populated at start-up from external JSON files - different ones on dev and server. Even an entire mock-up framework for automated tests.
Server-Side, it is a bit more complex, but for this API call, the important bits are (and written in Go obviously):
// --------------------------- API Startup ---------------------------- //
func Initialize() {
fmt.Println("package: API func: Initialize")
router := mux.NewRouter()
wl, err := fileIO.GetWordList("proto")
if err != nil {
msg := fmt.Sprintf("Unable to open word listFile - exiting, %v\n", err)
chores.CloseApp(msg)
}
s, err := fileIO.GetWelcome()
if err != nil {
msg := fmt.Sprintf("Error loading welcome message - exiting %v\n", err)
chores.CloseApp(msg)
}
getIP, err := fileIO.GetPrivateIP()
if err != nil {
msg := fmt.Sprintf("Error loading IP config - exiting %v\n", err)
chores.CloseApp(msg)
}
ip = getIP
welcome = s
wordsList = wl
state.ProtoHash = chores.HashWordList(wordsList)
state.Version = "v0.3"
server := &http.Server{
Handler: router,
Addr: ip.API,
WriteTimeout: 10 * time.Second,
ReadTimeout: 10 * time.Second,
}
router.HandleFunc("/getCat", getCategory) // getCat?catID=proto
router.HandleFunc("/getHash", getHash) // getHash?catID=proto
router.HandleFunc("/getVer", getVersion) // getVer?verID=vx.xx
router.HandleFunc("/getWel", getWelcome) // getWel?lang=0
router.HandleFunc("/postID", postID)
TLS, live := fileIO.GetTLSExists()
if live {
fmt.Println("TLS Certs loaded - running over https")
log.Fatal(server.ListenAndServeTLS(TLS.Fullchain, TLS.PrivKey))
} else {
fmt.Println("No TLS Certs - running over http")
log.Fatal(server.ListenAndServe())
}
}
func getHash(w http.ResponseWriter, r *http.Request) {
fmt.Println("package: API func: getHash")
var out string
method := r.Method
cat := r.FormValue("catID")
if qualifyGET(w, method, cat) {
out = chores.HashWordList(LoadWordsList(cat))
}
fmt.Fprint(w, out)
}
func qualifyGET(w http.ResponseWriter, method string, str string) bool {
if method != "GET" {
http.Error(w, http.StatusText(405), 405)
fmt.Println("ERROR:not GET method")
return false
}
return qualifyQuery(w, str)
}
func qualifyQuery(w http.ResponseWriter, in string) bool {
// prevent empty query string
if in == "" {
http.Error(w, http.StatusText(400), 400)
fmt.Println("ERROR:empty query")
return false
}
// set max chars limit
if len(in) > 50 {
http.Error(w, http.StatusText(400), 400)
fmt.Println("ERROR:query too long")
return false
}
return true
}
...and that is just a portion of my API code. But as you can see, it is fairly straight forward. Search for "Golang Restful API tutorial" and you'll find plenty of blogs, videos and websites going through different methods to make APIs in Go fairly well explained and step-by-step.