Connection make global connector by passed config
import RestConnection from 'flespi-io-js/dist/rest'
The arguments are:
config
is a global config for all connections you haveconnectorName
is a name of global variable of connector(only for initialization Vue plugin)token
is a token for connectionsflespiApp
is a app name, setting up x-flespi-app headerserver
server for http connectionsport (optional)
port for http connections...axios settings
some axios settings
let connector = new RestConnection({
token: 'FlespiToken xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
server: 'https://server.io',
port: 8080
})
- Token
let token = connector.token
connector.token = 'FlespiToken XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
- settings
let httpConfig = connector.config
connector.config = { server: 'http://server.io', port: 80 }
- setRegion methods allows set flespi region for connection.
connector.setRegion(region)
/* region structure */
{
"cdn": "https://ru-cdn.flespi.io",
"default": false,
"gw": "ru-gw.flespi.io",
"mqtt": "ru-mqtt.flespi.io:8883",
"mqtt-ws": "ru-mqtt.flespi.io:443",
"region": "ru",
"rest": "https://ru.flespi.io"
}
Method for making http requests. It`s using axios as a dependency. So API of HTTP is the same as axios HTTP API axios
Connector#http.request(options)
: same options axiosConnector#http.get(url, [options])
,Connector#http.delete(url, [options])
,Connector#http.post(url, data, [options])
,Connector#http.put(url, data, [options])
url
is the server URL that will be used for the requestdata
is the data to be sent as the request bodyoptions
are another options by axios API
Connector#http.external(options)
: to make requests to somewhere. Get full api of axios.
It has all sugar methods.