Skip to content

Run example

DravenK edited this page Aug 16, 2020 · 4 revisions

Run example:

 cd $GOPATH/src/github.com/dravenk/webthing-go
 
 go run examples/single-thing/single-thing.go

You can also run a sample with docker:

docker run -ti --name single-thing -p 8888:8888 -d dravenk/webthing

All Web Thing REST API are currently supported. The currently built Server supports lookup using Thing's title or index in Things.

# The default address is http://localhost:8888/things
curl --request GET --url http://localhost:8888/things

# Example: Get a description of a Thing
# use the Thing index.
curl --request GET --url http://localhost:8888
# Or use the Thing title.
curl --request GET --url http://localhost:8888/Lamp

Example: Properties

# Example: Get all properties
curl --request GET --url http://localhost:8888/properties
# Or
curl --request GET --url http://localhost:8888/Lamp/properties

# Example: Get a property
curl --request GET --url http://localhost:8888/properties/brightness

# Example: Set a property
curl --request PUT \
  --url http://localhost:8888/properties/brightness \
  --data '{"brightness": 33}'

Example: Actions

 # Example: Action Request
 curl --request POST \
   --url http://localhost:8888/actions \
   --data '{"fade":{"input":{"brightness":55,"duration":2000}}}'

 # Example: Cancel an Action Request
    curl --request DELETE \
      --url http://localhost:8888/actions/fade/{action_id}

 # Example: Action Request
 curl --request POST \
   --url http://localhost:8888/actions \
   --data '{"toggle":{}}'

 # Example: Actions Queue
 curl --request GET \
   --url http://localhost:8888/actions

Example: Events

# Example: Events Request
curl --request GET \
  --url http://localhost:8888/events
  
 # Example: Event Request
 curl --request GET \
   --url http://localhost:8888/events/overheated
Clone this wiki locally