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.
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.
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 | ||||||||
| 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": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"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": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"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": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"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": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
{
"id": 1,
"src": "shellydev1-f008d1e2cb4c",
"params": {
"code": 200,
"message": "OK",
"headers": {
"Server": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
}
{
"code": 200,
"message": "OK",
"headers": {
"Server": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"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": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
{
"id": 1,
"src": "shellydev1-f008d1e2cb4c",
"params": {
"code": 200,
"message": "OK",
"headers": {
"Server": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}
}
{
"code": 200,
"message": "OK",
"headers": {
"Server": "Mongoose/6.18",
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "*",
"Content-Length": "28",
"Connection": "close"
},
"body": "{\"restart_required\":false}\r\n"
}