Skip to content

Run example

DravenK edited this page Aug 1, 2023 · 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 -X GET http://localhost:8888/things
 
# Example: Get a description of a Thing
# use the Thing index.
curl -X GET http://localhost:8888
# Or use the Thing title.
curl -X GET http://localhost:8888/Lamp

Example: Properties

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

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

Example: Actions

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

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

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

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

Example: Events

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