Skip to content

Commit f03b34b

Browse files
committed
add more HTTP docs
1 parent 9e321a7 commit f03b34b

File tree

1 file changed

+24
-9
lines changed
  • docs/beginners-guide/articles/protocols

1 file changed

+24
-9
lines changed

docs/beginners-guide/articles/protocols/http.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,28 @@ Oscilloscope(
2929

3030
The default routes are created as follows:
3131

32-
| Resource | Path | Description |
33-
| ----------------- | ------------------------------ | ---------------------------- |
34-
| Property | `/<thing-id>/<foo-bar>` | for property `foo_bar` |
35-
| Action | `/<thing-id>/<foo-bar>` | for action `foo_bar` |
36-
| Event | `/<thing-id>/<foo-bar>` | for event `foo_bar` |
37-
| Thing Model | `/<thing-id>/resources/wot-tm` | to get the Thing Model |
38-
| Thing Description | `/<thing-id>/resources/wot-td` | to get the Thing Description |
32+
| Resource | Path | Description | Handler | Default Method |
33+
| ----------------- | ------------------------------ | ---------------------------- | ------------------------- | -------------------------------------------------------------- |
34+
| Property | `/<thing-id>/<foo-bar>` | for property `foo_bar` | `PropertyHandler` | `GET` for read <br/> `PUT` for write <br/> `DELETE` for delete |
35+
| Action | `/<thing-id>/<foo-bar>` | for action `foo_bar` | `ActionHandler` | `POST` |
36+
| Event | `/<thing-id>/<foo-bar>` | for event `foo_bar` | `EventHandler` | `GET` |
37+
| Thing Model | `/<thing-id>/resources/wot-tm` | to get the Thing Model | - acts as property - | `GET` |
38+
| Thing Description | `/<thing-id>/resources/wot-td` | to get the Thing Description | `ThingDescriptionHandler` | `GET` |
39+
40+
All underscores are converted to hyphens in the URL paths for every resource, and the Thing ID is a global prefix.
41+
42+
One can register custom routes and methods as follows:
43+
44+
```python linenums="1" title="Custom Routes"
45+
from hololinked.server import HTTPServer
46+
47+
server = HTTPServer(port=8090)
48+
49+
server.add_property('/channels/data/A', Oscilloscope.channel_A)
50+
server.add_event('/channels/data/A/stream', Oscilloscope.channel_A_data_event)
51+
52+
Oscilloscope(id='oscilloscope').run(servers=[server])
53+
```
3954

4055
## Allow CORS
4156

@@ -62,9 +77,9 @@ If one wishes to remotely stop the HTTP server, one needs to exit both the serve
6277
```python linenums="1" title="Remotely Stop HTTP Server"
6378
import requests
6479

65-
response = requests.post('https://my-pc:8090/my-thing-id/exit')
80+
response = requests.post('https://my-pc:9090/my-thing-id/exit')
6681
assert response.status_code == 204
67-
response = requests.post('https://my-pc:8090/stop')
82+
response = requests.post('https://my-pc:9090/stop')
6883
assert response.status_code == 204
6984
```
7085

0 commit comments

Comments
 (0)