gobot.io/x/gobot@v1.16.0/api/doc.go (about) 1 /* 2 Package api provides a webserver to interact with your Gobot program over the network. 3 4 Example: 5 6 package main 7 8 import ( 9 "fmt" 10 11 "gobot.io/x/gobot" 12 "gobot.io/x/gobot/api" 13 ) 14 15 func main() { 16 gbot := gobot.NewMaster() 17 18 // Starts the API server on default port 3000 19 api.NewAPI(gbot).Start() 20 21 // Accessible via http://localhost:3000/api/commands/say_hello 22 gbot.AddCommand("say_hello", func(params map[string]interface{}) interface{} { 23 return "Master says hello!" 24 }) 25 26 hello := gbot.AddRobot(gobot.NewRobot("Eve")) 27 28 // Accessible via http://localhost:3000/api/robots/Eve/commands/say_hello 29 hello.AddCommand("say_hello", func(params map[string]interface{}) interface{} { 30 return fmt.Sprintf("%v says hello!", hello.Name) 31 }) 32 33 gbot.Start() 34 } 35 36 It follows Common Protocol for Programming Physical Input and Output (CPPP-IO) spec: 37 https://gobot.io/x/cppp-io 38 */ 39 package api