HTTP
The HTTP service provides functionality for sending HTTP/HTTPS requests through the RPC methods HTTP.GET
and HTTP.POST
. Also a generic HTTP.Request
RPC call is provided which allows sending several HTTP methods.
Authentication support
Since version 1.0
URL strings with username
and passwrod
elements are supported as defined in WHATWG. The HTTP client will use the authentication credentials for resources protected by the basic and digest authentication schemes.
Errors
Methods in the HTTP service will return an error response with code -103
for invalid or missing arguments or -108
if an unacceptable number of request headers was given. If the call is accepted, but the HTTP request fails, the error response will contain one of the following codes:
-104
"Deadline exceeded" when the request times out-108
"Resource exhausted" if the response body payload was too large to handle-114
"Unavailable" for other error conditions.
The error message will be prefixed with an additional, internal error code indicating the specific error condition:
-10
: Name not resolved-11
: Sending data to remote peer failed-12
: Header parse error-13
: Unsupported encoding-14
: Response too big-15
: Body parse error-16
: Connection closed prematurely-17
: Too many redirects-18
: HTTP Error Response
HTTP.GET
This method allows fetching resources using HTTP/HTTPS GET requests.
Request
Parameters:
Property | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
| string | Url address of the request. Required | ||||||||
| number | Timeout in seconds. Optional | ||||||||
| string or null | Type of the TCP socket. Optional
|
Response
Attributes in the result:
Property | Type | Description |
---|---|---|
| number | Code of the HTTP response |
| string | Msssage of the HTTP response |
| object | List of HTTP headers sent by the server |
| string | HTTP response body, if |
| string | base64 encoded HTTP response body, if body is binary data. Maximum accepted length is 16KB (16384 bytes) |
HTTP.POST
This method allows posting data and receiving response using HTTP/HTTPS POST requests.
Request
Parameters:
Property | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
| string | URL address of the request. Required | ||||||||
| string | The request body. Required | ||||||||
| string | base64 encoded binary request body. Either | ||||||||
| string | Value of the Content-Type header sent with the request Optional, default is application/json | ||||||||
| number | Timeout in seconds. Optional | ||||||||
| string or null | Type of the TCP socket. Optional
|
Response
Attributes in the result:
Property | Type | Description |
---|---|---|
| number | Code of the HTTP response |
| string | Message of the HTTP response |
| object | List of HTTP headers sent by the server |
| string | HTTP response body, if |
| string | base64 encoded HTTP response body, if body is binary data. Maximum accepted length is 16KB (16384 bytes) |
HTTP.Request
This method allows sending several HTTP methods through HTTP/HTTPS and receiving response. Currently supported are GET, POST, PUT, HEAD and DELETE.
HTTP.Request
also exposes a few additional aspects of the HTTP request being made:
- Can specify timeout for the operation -- seconds of inactivity which will abort the operation;
- Can specify request headers. A maximum of 15 headers, with value sizes limited to 384 bytes each will be accepted.
- Use
PUT
,HEAD
andDELETE
HTTP methods.
Request
Parameters:
Property | Type | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
| string | Method to send. Valid values are | ||||||||
| string | URL address of the request. Required | ||||||||
| string | The request body. Disallowed for | ||||||||
| string | base64 encoded binary request body. Either | ||||||||
| object | User supplied headers for the request, keys are header names and values are header values. Optional. | ||||||||
| number | Timeout in seconds. Optional. Defaults to 15 seconds of inactivity. | ||||||||
| string or null | Type of the TCP socket. Optional
|
Response
Attributes in the result:
Property | Type | Description |
---|---|---|
| number | Code of the HTTP response |
| string | Message of the HTTP response |
| object | List of HTTP headers sent by the server |
| string | HTTP response body, if |
| string | base64 encoded HTTP response body, if body is binary data. Maximum accepted length is 16KB (16384 bytes) |
Examples
HTTP.GET example
- HTTP.GET HTTP GET Request
- HTTP.GET Curl Request
- HTTP.GET Mos Request
http://192.168.33.1/rpc/HTTP.GET?url="http://10.33.53.21/rpc/Shelly.GetDeviceInfo"
curl -X POST -d '{"id":1,"method":"HTTP.GET","params":{"url":"http://10.33.53.21/rpc/Shelly.GetDeviceInfo"}}' http://${SHELLY}/rpc
mos --port ${PORT} call HTTP.GET '{"url":"http://10.33.53.21/rpc/Shelly.GetDeviceInfo"}'
Response
- HTTP.GET HTTP GET Response
- HTTP.GET Curl Response
- HTTP.GET Mos Response
{
"code": 200,
"message": "OK",
"headers": {
"Server": "ShellyHTTP/1.0.0",
"Content-Type": "application/json",
"Content-Length": "232",
"Connection": "close"
},
"body": "{\"id\":\"shellydev1-f008d1e2cb4c\", \"mac\":\"F008D1E2CB4C\", \"model\":\"SNSW-devX16EU\", \"gen\":2, \"fw_id\":\"20210908-124312/0.7.0-29-g0df1661-145-rpc-http-get-improvements-2\", \"ver\":\"0.7.0\", \"app\":\"Dev1\", \"auth_en\":false,\"auth_domain\":null}\r\n"
}
{
"id": 1,
"src": "shellydev1-f008d1e2cb4c",
"params": {
"code": 200,
"message": "OK",
"headers": {
"Server": "ShellyHTTP/1.0.0",
"Content-Type": "application/json",
"Content-Length": "232",
"Connection": "close"
},
"body": "{\"id\":\"shellydev1-f008d1e2cb4c\", \"mac\":\"F008D1E2CB4C\", \"model\":\"SNSW-devX16EU\", \"gen\":2, \"fw_id\":\"20210908-124312/0.7.0-29-g0df1661-145-rpc-http-get-improvements-2\", \"ver\":\"0.7.0\", \"app\":\"Dev1\", \"auth_en\":false,\"auth_domain\":null}\r\n"
}
}
{
"code": 200,
"message": "OK",
"headers": {
"Server": "ShellyHTTP/1.0.0",
"Content-Type": "application/json",
"Content-Length": "232",
"Connection": "close"
},
"body": "{\"id\":\"shellydev1-f008d1e2cb4c\", \"mac\":\"F008D1E2CB4C\", \"model\":\"SNSW-devX16EU\", \"gen\":2, \"fw_id\":\"20210908-124312/0.7.0-29-g0df1661-145-rpc-http-get-improvements-2\", \"ver\":\"0.7.0\", \"app\":\"Dev1\", \"auth_en\":false,\"auth_domain\":null}\r\n"
}
HTTP.POST example
- HTTP.POST HTTP GET Request
- HTTP.POST Curl Request
- HTTP.POST Mos Request
http://192.168.33.1/rpc/HTTP.POST?url="http://10.33.53.21/rpc/Sys.SetConfig"&body="{\"config\":{\"location\":{\"tz\":\"UTC\"}}}"
curl -X POST -d '{"id":1,"method":"HTTP.POST","params":{"url":"http://10.33.53.21/rpc/Sys.SetConfig","body":"{\"config\":{\"location\":{\"tz\":\"UTC\"}}}"}}' http://${SHELLY}/rpc
mos --port ${PORT} call HTTP.POST '{"url":"http://10.33.53.21/rpc/Sys.SetConfig","body":"{\"config\":{\"location\":{\"tz\":\"UTC\"}}}"}'
Response
- HTTP.POST HTTP GET Response
- HTTP.POST Curl Response
- HTTP.POST Mos Response
{
"code": 200,
"message": "OK",
"headers": {
"Server": "ShellyHTTP/1.0.0",
"Content-Type": "application/json",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
{
"id": 1,
"src": "shellydev1-f008d1e2cb4c",
"params": {
"code": 200,
"message": "OK",
"headers": {
"Server": "ShellyHTTP/1.0.0",
"Content-Type": "application/json",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
}
{
"code": 200,
"message": "OK",
"headers": {
"Server": "ShellyHTTP/1.0.0",
"Content-Type": "application/json",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
HTTP.Request example
- HTTP.Request HTTP GET Request
- HTTP.Request Curl Request
- HTTP.Request Mos Request
http://192.168.33.1/rpc/HTTP.Request?method="POST"&url="http://10.33.53.21/rpc/Sys.SetConfig"&body="{\"config\":{\"location\":{\"tz\":\"UTC\"}}}"
curl -X POST -d '{"id":1,"method":"HTTP.Request","params":{"method":"POST","url":"http://10.33.53.21/rpc/Sys.SetConfig","body":"{\"config\":{\"location\":{\"tz\":\"UTC\"}}}"}}' http://${SHELLY}/rpc
mos --port ${PORT} call HTTP.Request '{"method":"POST","url":"http://10.33.53.21/rpc/Sys.SetConfig","body":"{\"config\":{\"location\":{\"tz\":\"UTC\"}}}"}'
Response
- HTTP.Request HTTP GET Response
- HTTP.Request Curl Response
- HTTP.Request Mos Response
{
"code": 200,
"message": "OK",
"headers": {
"Server": "ShellyHTTP/1.0.0",
"Content-Type": "application/json",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
{
"id": 1,
"src": "shellydev1-f008d1e2cb4c",
"params": {
"code": 200,
"message": "OK",
"headers": {
"Server": "ShellyHTTP/1.0.0",
"Content-Type": "application/json",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
}
{
"code": 200,
"message": "OK",
"headers": {
"Server": "ShellyHTTP/1.0.0",
"Content-Type": "application/json",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
HTTP.GET With authentication credentials example
- HTTP.GET HTTP GET Request
- HTTP.GET Curl Request
- HTTP.GET Mos Request
http://192.168.33.1/rpc/HTTP.GET?url="http://admin:supersecretpassword@10.33.53.21/rpc/Shelly.Reboot"
curl -X POST -d '{"id":1,"method":"HTTP.GET","params":{"url":"http://admin:supersecretpassword@10.33.53.21/rpc/Shelly.Reboot"}}' http://${SHELLY}/rpc
mos --port ${PORT} call HTTP.GET '{"url":"http://admin:supersecretpassword@10.33.53.21/rpc/Shelly.Reboot"}'
Response
- HTTP.GET HTTP GET Response
- HTTP.GET Curl Response
- HTTP.GET Mos Response
{
"code": 200,
"message": "OK",
"headers": {
"Connection": "close",
"Content-Length": "4",
"Content-Type": "application/json",
"Server": "ShellyHTTP/1.0.0"
},
"body": "null"
}
{
"id": 1,
"src": "shellydev1-f008d1e2cb4c",
"params": {
"code": 200,
"message": "OK",
"headers": {
"Connection": "close",
"Content-Length": "4",
"Content-Type": "application/json",
"Server": "ShellyHTTP/1.0.0"
},
"body": "null"
}
}
{
"code": 200,
"message": "OK",
"headers": {
"Connection": "close",
"Content-Length": "4",
"Content-Type": "application/json",
"Server": "ShellyHTTP/1.0.0"
},
"body": "null"
}