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 | 14 | one WiFi network device. (e.g. both need to operate on the same channel). See | 14 | one WiFi network device. (e.g. both need to operate on the same channel). See |
7 | 15 | [Simultaneous STA / AP Mode](simultaneous-sta-ap-mode.md) for more details. | 15 | [Simultaneous STA / AP Mode](simultaneous-sta-ap-mode.md) for more details. |
8 | 16 | 16 | ||
9 | 17 | ## 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 | 18 | |||
11 | 19 | Review your request and be sure double quotes are correctly escaped. The following | ||
12 | 20 | request will result in an error as quotes are not properly escaped: | ||
13 | 21 | |||
14 | 22 | ``` | ||
15 | 23 | $ 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 | 24 | |||
17 | 25 | |||
18 | 26 | HTTP/1.1 500 Internal Server Error | ||
19 | 27 | Date: Fri, 22 Sep 2017 08:35:57 GMT | ||
20 | 28 | Content-Length: 146 | ||
21 | 29 | Content-Type: text/plain; charset=utf-8 | ||
22 | 30 | |||
23 | 31 | {"result":{"kind":"internal-error","message":"Error reading the request body"},"status":"Internal Server Error","status-code":500,"type":"error"} | ||
24 | 32 | ``` | ||
25 | 33 | |||
26 | 34 | If quotes are properly escaped then the request will be accepted by the service: | ||
27 | 35 | |||
28 | 36 | ``` | ||
29 | 37 | $ 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 | 38 | |||
31 | 39 | |||
32 | 40 | HTTP/1.1 200 OK | ||
33 | 41 | Date: Fri, 22 Sep 2017 08:39:05 GMT | ||
34 | 42 | Content-Length: 60 | ||
35 | 43 | Content-Type: text/plain; charset=utf-8 | ||
36 | 44 | |||
37 | 45 | {"result":{},"status":"OK","status-code":200,"type":"sync"} | ||
38 | 46 | ``` | ||
39 | 47 | Also, it's recommended to put the JSON post data into a text file and redirect command input | ||
40 | 48 | from that file during your testing as it makes the post data easier to read and edit. | ||
41 | 49 | ``` bash | ||
42 | 50 | $ sudo nc -U /var/snap/wifi-ap/current/sockets/control < _post_content_file_ | ||
43 | 51 | ``` | ||
44 | 52 | |||
45 | 53 | You can find more information related to this [here](rest-api-from-command-line.md) | ||
46 | 54 | |||
47 | 17 | ## Why isn't the AP automatically enabled after I've installed the snap? | 55 | ## Why isn't the AP automatically enabled after I've installed the snap? |
48 | 18 | 56 | ||
49 | 19 | Normally it should automatically come up if this isn't disabled through the | 57 | 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 | 15 | location: secure-access-point.md | 15 | location: secure-access-point.md |
56 | 16 | - title: Simultaneous STA / AP Mode | 16 | - title: Simultaneous STA / AP Mode |
57 | 17 | location: simultaneous-sta-ap-mode.md | 17 | location: simultaneous-sta-ap-mode.md |
58 | 18 | - title: Usage | ||
59 | 19 | children: | ||
60 | 20 | - title: REST API from command line | ||
61 | 21 | location: rest-api-from-command-line.md | ||
62 | 18 | - title: Reference | 22 | - title: Reference |
63 | 19 | children: | 23 | children: |
64 | 20 | - title: Commands | 24 | - title: Commands |
65 | diff --git a/docs/rest-api-from-command-line.md b/docs/rest-api-from-command-line.md | |||
66 | 21 | new file mode 100644 | 25 | 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 | 1 | --- | ||
72 | 2 | title: "REST API From Command Line" | ||
73 | 3 | table_of_contents: False | ||
74 | 4 | --- | ||
75 | 5 | |||
76 | 6 | # REST API From Command Line | ||
77 | 7 | |||
78 | 8 | The wifi-ap snap exposes a REST API for its management that can be accessed | ||
79 | 9 | through a local Unix domain socket. One of the options to make use of that | ||
80 | 10 | API is using the command line as client. | ||
81 | 11 | |||
82 | 12 | You can see the details of the available API operations [here] (reference/rest-api.md) | ||
83 | 13 | |||
84 | 14 | # Prerequisites | ||
85 | 15 | |||
86 | 16 | You can use `nc` to send queries and print the response from the command line. `nc` is included | ||
87 | 17 | in the default set of installed packages in Ubuntu Classic and as part of the core snap when | ||
88 | 18 | you use Ubuntu Core or snaps. If not available please install via: | ||
89 | 19 | |||
90 | 20 | ``` | ||
91 | 21 | $ apt install netcat | ||
92 | 22 | ``` | ||
93 | 23 | |||
94 | 24 | # Perform REST API Operations | ||
95 | 25 | |||
96 | 26 | From command line, you can query for current snap configuration by executing: | ||
97 | 27 | |||
98 | 28 | ``` | ||
99 | 29 | $ 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 | 30 | ``` | ||
101 | 31 | |||
102 | 32 | That should result in a successful response whose JSON formatted content holds a current | ||
103 | 33 | configuration of the wifi-ap service: | ||
104 | 34 | ``` | ||
105 | 35 | HTTP/1.1 200 OK | ||
106 | 36 | Date: Fri, 22 Sep 2017 09:39:33 GMT | ||
107 | 37 | Content-Length: 497 | ||
108 | 38 | Content-Type: text/plain; charset=utf-8 | ||
109 | 39 | |||
110 | 40 | {"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 | 41 | ``` | ||
112 | 42 | |||
113 | 43 | The configuration can be modified by sending a POST request with the params to | ||
114 | 44 | set and its new values in a JSON formatted content type body. Some HTTP headers must | ||
115 | 45 | be set in the request: | ||
116 | 46 | * *Host*: Hostname where wifi-ap snap is installed | ||
117 | 47 | * *Content-type*: Its value must be set to `application/json` | ||
118 | 48 | * *Content-length*: Must match the exact number of characters the request body has | ||
119 | 49 | |||
120 | 50 | ``` | ||
121 | 51 | $ 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 | 52 | ``` | ||
123 | 53 | |||
124 | 54 | A sucessful server reply means that the configuration has been updated as desired: | ||
125 | 55 | |||
126 | 56 | ``` | ||
127 | 57 | HTTP/1.1 200 OK | ||
128 | 58 | Date: Fri, 22 Sep 2017 09:43:31 GMT | ||
129 | 59 | Content-Length: 60 | ||
130 | 60 | Content-Type: text/plain; charset=utf-8 | ||
131 | 61 | |||
132 | 62 | {"result":{},"status":"OK","status-code":200,"type":"sync"} | ||
133 | 63 | ``` | ||
134 | 64 | |||
135 | 65 | |||
136 | 66 | !!! Note: | ||
137 | 67 | In case you need to provide body content, you have to escape the | ||
138 | 68 | 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)
...
...