Example how to use REST API client for Apache Ignite (GridGain)
Instruction for Apache Ignite 2.0.0:
-
Download Apache Ignite 2.0.0 from official site
-
Extract distributive to any folder
-
Copy or move folder ignite-rest-http from <path_with_ignite>/libs/optional/ to <path_with_ignite>/libs/. It enables Ignite HTTP REST API.
-
cd to folder with current example files
-
Start Ignite server with configuration files from this example:
For Windows:
<path_with_ignite>\bin\ignite.bat .\example-http-client.xml
For Linux:
<path_with_ignite>/bin/ignite.sh ./example-http-client.xml
- Run example:
go run main.go
Source code:
package main
import (
"log"
"github.com/amsokol/go-ignite-client/http/v2"
"net/url"
)
func main() {
servers := []string{"http://localhost:8080/ignite"}
c := v2.Open(servers, "", "") // no login and password
v, _, err := c.GetVersion()
if err != nil {
log.Fatal(err)
}
log.Println("Server version is", v)
_, _, err = c.SQLFieldsQueryExecute("Person", 1000, `DELETE FROM Person`, url.Values{})
if err != nil {
log.Fatal(err)
}
log.Println("Deleted all rows from Person")
log.Println("")
_, _, err = c.SQLFieldsQueryExecute("Organization", 1000, `DELETE FROM Organization`, url.Values{})
if err != nil {
log.Fatal(err)
}
log.Println("Deleted all rows from Organization")
log.Println("")
_, _, err = c.SQLFieldsQueryExecute("Organization", 1000, `INSERT INTO Organization(_key, name) VALUES(1, 'Org 1')`, url.Values{})
if err != nil {
log.Fatal(err)
}
log.Println("Added one record to Organization")
log.Println("")
r, _, err := c.SQLFieldsQueryExecute("Organization", 1000, `SELECT _key, name FROM Organization`, url.Values{})
if err != nil {
log.Fatal(err)
}
log.Println("Organizations:")
log.Println(r)
}