Merge ~rmescandon/snappy-hwe-snaps/+git/wifi-ap:document-api-request-from-cli into ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master
- Git
- lp:~rmescandon/snappy-hwe-snaps/+git/wifi-ap
- document-api-request-from-cli
- Merge into master
Status: | Needs review |
---|---|
Proposed branch: | ~rmescandon/snappy-hwe-snaps/+git/wifi-ap:document-api-request-from-cli |
Merge into: | ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master |
Diff against target: |
138 lines (+110/-0) 3 files modified
docs/faq.md (+38/-0) docs/metadata.yaml (+4/-0) docs/rest-api-from-command-line.md (+68/-0) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
System Enablement Bot | continuous-integration | Needs Fixing | |
Simon Fels | Approve | ||
Jim Hodapp (community) | Approve | ||
Gary.Wang | Approve | ||
Review via email: mp+331186@code.launchpad.net |
Commit message
Description of the change
Added a pair of FAQs related with errors reported using REST API from cli
- 4f91907... by Roberto Mier Escandon
-
added Usage section in navigation
moved rest api use from cli to a newer page
rephrased
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 6759986e9fb2592
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:6759986e9fb
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
- 71f74a3... by Roberto Mier Escandon
-
updated docs with more info and more addressed comments
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 4f91907db6d7c24
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:4f91907db6d
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 5bf7ab72c3d0f51
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:5bf7ab72c3d
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 71f74a3020cf3c6
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:71f74a3020c
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
Jim Hodapp (jhodapp) wrote : | # |
Looking good, some things to fix.
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 71f74a3020cf3c6
Generated documentation is available at https:/
- c67db71... by Roberto Mier Escandon
-
corrected english
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:71f74a3020c
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
Jim Hodapp (jhodapp) wrote : | # |
One more thing to fix.
- 92106f8... by Roberto Mier Escandon
-
final? addressing
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: c67db71684ef117
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:c67db71684e
https:/
Executed test runs:
SUCCESS: https:/
SUCCESS: https:/
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:92106f8f50d
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:92106f8f50d
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:92106f8f50d
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Successfully build documentation, rev: 92106f8f50d979d
Generated documentation is available at https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
FAILED: Continuous integration, rev:92106f8f50d
https:/
Executed test runs:
FAILURE: https:/
FAILURE: https:/
SUCCESS: https:/
FAILURE: https:/
Click here to trigger a rebuild:
https:/
Unmerged commits
- 92106f8... by Roberto Mier Escandon
-
final? addressing
- c67db71... by Roberto Mier Escandon
-
corrected english
- 71f74a3... by Roberto Mier Escandon
-
updated docs with more info and more addressed comments
- 4f91907... by Roberto Mier Escandon
-
added Usage section in navigation
moved rest api use from cli to a newer page
rephrased - 6759986... by Roberto Mier Escandon
-
added a pair of faqs related with api rest access from cli
Preview Diff
1 | diff --git a/docs/faq.md b/docs/faq.md |
2 | index a2b705c..9ad08bb 100644 |
3 | --- a/docs/faq.md |
4 | +++ b/docs/faq.md |
5 | @@ -14,6 +14,44 @@ Yes this is possible. However, there are known limitations if the device only ha |
6 | one WiFi network device. (e.g. both need to operate on the same channel). See |
7 | [Simultaneous STA / AP Mode](simultaneous-sta-ap-mode.md) for more details. |
8 | |
9 | +## I am sending an HTTP post request from the command line to the wifi-ap management service but I receive a HTTP 500 error code. Why? |
10 | + |
11 | +Review your request and be sure double quotes are correctly escaped. The following |
12 | +request will result in an error as quotes are not properly escaped: |
13 | + |
14 | +``` |
15 | +$ printf "POST /v1/configuration HTTP/1.1\r\nHost: www.example.com\r\nContent-type: application/json\r\nContent-length: 20\r\n\r\n{"disabled":"false"}" | sudo nc -U /var/snap/wifi-ap/current/sockets/control |
16 | + |
17 | + |
18 | +HTTP/1.1 500 Internal Server Error |
19 | +Date: Fri, 22 Sep 2017 08:35:57 GMT |
20 | +Content-Length: 146 |
21 | +Content-Type: text/plain; charset=utf-8 |
22 | + |
23 | +{"result":{"kind":"internal-error","message":"Error reading the request body"},"status":"Internal Server Error","status-code":500,"type":"error"} |
24 | +``` |
25 | + |
26 | +If quotes are properly escaped then the request will be accepted by the service: |
27 | + |
28 | +``` |
29 | +$ printf "POST /v1/configuration HTTP/1.1\r\nHost: www.example.com\r\nContent-type: application/json\r\nContent-length: 20\r\n\r\n{\"disabled\":\"false\"}" | sudo nc -U /var/snap/wifi-ap/current/sockets/control |
30 | + |
31 | + |
32 | +HTTP/1.1 200 OK |
33 | +Date: Fri, 22 Sep 2017 08:39:05 GMT |
34 | +Content-Length: 60 |
35 | +Content-Type: text/plain; charset=utf-8 |
36 | + |
37 | +{"result":{},"status":"OK","status-code":200,"type":"sync"} |
38 | +``` |
39 | +Also, it's recommended to put the JSON post data into a text file and redirect command input |
40 | +from that file during your testing as it makes the post data easier to read and edit. |
41 | +``` bash |
42 | +$ sudo nc -U /var/snap/wifi-ap/current/sockets/control < _post_content_file_ |
43 | +``` |
44 | + |
45 | +You can find more information related to this [here](rest-api-from-command-line.md) |
46 | + |
47 | ## Why isn't the AP automatically enabled after I've installed the snap? |
48 | |
49 | Normally it should automatically come up if this isn't disabled through the |
50 | diff --git a/docs/metadata.yaml b/docs/metadata.yaml |
51 | index 4ecfe02..0cf387c 100644 |
52 | --- a/docs/metadata.yaml |
53 | +++ b/docs/metadata.yaml |
54 | @@ -15,6 +15,10 @@ navigation: |
55 | location: secure-access-point.md |
56 | - title: Simultaneous STA / AP Mode |
57 | location: simultaneous-sta-ap-mode.md |
58 | + - title: Usage |
59 | + children: |
60 | + - title: REST API from command line |
61 | + location: rest-api-from-command-line.md |
62 | - title: Reference |
63 | children: |
64 | - title: Commands |
65 | diff --git a/docs/rest-api-from-command-line.md b/docs/rest-api-from-command-line.md |
66 | new file mode 100644 |
67 | index 0000000..fb317ac |
68 | --- /dev/null |
69 | +++ b/docs/rest-api-from-command-line.md |
70 | @@ -0,0 +1,68 @@ |
71 | +--- |
72 | +title: "REST API From Command Line" |
73 | +table_of_contents: False |
74 | +--- |
75 | + |
76 | +# REST API From Command Line |
77 | + |
78 | +The wifi-ap snap exposes a REST API for its management that can be accessed |
79 | +through a local Unix domain socket. One of the options to make use of that |
80 | +API is using the command line as client. |
81 | + |
82 | +You can see the details of the available API operations [here] (reference/rest-api.md) |
83 | + |
84 | +# Prerequisites |
85 | + |
86 | +You can use `nc` to send queries and print the response from the command line. `nc` is included |
87 | +in the default set of installed packages in Ubuntu Classic and as part of the core snap when |
88 | +you use Ubuntu Core or snaps. If not available please install via: |
89 | + |
90 | +``` |
91 | +$ apt install netcat |
92 | +``` |
93 | + |
94 | +# Perform REST API Operations |
95 | + |
96 | +From command line, you can query for current snap configuration by executing: |
97 | + |
98 | +``` |
99 | +$ printf "GET /v1/configuration HTTP/1.1\r\n Host: www.example.com\r\n\r\n" | sudo nc -U /var/snap/wifi-ap/current/sockets/control |
100 | +``` |
101 | + |
102 | +That should result in a successful response whose JSON formatted content holds a current |
103 | +configuration of the wifi-ap service: |
104 | +``` |
105 | +HTTP/1.1 200 OK |
106 | +Date: Fri, 22 Sep 2017 09:39:33 GMT |
107 | +Content-Length: 497 |
108 | +Content-Type: text/plain; charset=utf-8 |
109 | + |
110 | +{"result":{"debug":false,"dhcp.lease-time":"12h","dhcp.range-start":"10.0.60.3","dhcp.range-stop":"10.0.60.20","disabled":false,"share.disabled":false,"share.network-interface":"eth0","wifi.address":"10.0.60.1","wifi.channel":"6","wifi.hostapd-driver":"nl80211","wifi.interface":"wlan0","wifi.interface-mode":"direct","wifi.netmask":"255.255.255.0","wifi.operation-mode":"g","wifi.security":"open","wifi.security-passphrase":"","wifi.ssid":"Ubuntu"},"status":"OK","status-code":200,"type":"sync"} |
111 | +``` |
112 | + |
113 | +The configuration can be modified by sending a POST request with the params to |
114 | +set and its new values in a JSON formatted content type body. Some HTTP headers must |
115 | +be set in the request: |
116 | + * *Host*: Hostname where wifi-ap snap is installed |
117 | + * *Content-type*: Its value must be set to `application/json` |
118 | + * *Content-length*: Must match the exact number of characters the request body has |
119 | + |
120 | +``` |
121 | +$ printf "POST /v1/configuration HTTP/1.1\r\nHost: www.example.com\r\nContent-type: application/json\r\nContent-length: 20\r\n\r\n{\"disabled\":\"false\"}" | sudo nc -U /var/snap/wifi-ap/current/sockets/control |
122 | +``` |
123 | + |
124 | +A sucessful server reply means that the configuration has been updated as desired: |
125 | + |
126 | +``` |
127 | +HTTP/1.1 200 OK |
128 | +Date: Fri, 22 Sep 2017 09:43:31 GMT |
129 | +Content-Length: 60 |
130 | +Content-Type: text/plain; charset=utf-8 |
131 | + |
132 | +{"result":{},"status":"OK","status-code":200,"type":"sync"} |
133 | +``` |
134 | + |
135 | + |
136 | +!!! Note: |
137 | + In case you need to provide body content, you have to escape the |
138 | + double quote to not receive a malformed request error. |
Thanks! Just left one comment.
Also, would you mind adjusting the content position a little bit? i.e.
## Why isn't the AP automatically enabled after I've installed the snap?
...
...
...
## Can I send REST API queries from the command line?
...
...
...
If this still doesn't help, feel free to file a [bug report] (report- bug.md)
...
...