overwolf.web API
Use this API to open a local HTTP web-server and a WebSocket.
Methods Reference
Types Reference
- overwolf.web.WebSocketConnectionParams Object
- overwolf.web.enums.HttpRequestMethods enum
- overwolf.web.enums.MessageType enum
- overwolf.web.FetchHeader Object
- overwolf.web.CreateServerResult Object
- overwolf.web.SendHttpRequestResult Object
- overwolf.web.CreateWebSocketResult Object
createServer(port, callback)
Version added: 0.93
Permissions required: Web
Creates a web server.
Parameter | Type | Description |
---|---|---|
port | int | The port to use |
callback | CreateServerResult Object | Container for the server object |
Usage Example
Here you can see a sample code for using the overwolf.web and overwolf.web.webserver APIs:
let _port = 61234;
overwolf.web.createServer(_port, serverInfo => {
if (serverInfo.status == "error") {
console.log("Failed to create server");
return;
} else {
_server = serverInfo.server;
// it is always good practice to removeListener before adding it
_server.onRequest.removeListener(onRequest);
_server.onRequest.addListener(onRequest);
_server.listen(info => {
console.log("Server listening status on port " + _port + " : " + info);
//info = { "status": "success", "url": "http://localhost:61234/"}
});
}
});
function onRequest(info) {
console.log(info.content);
// info = { "content": "{'hello': 'world'}", "contentType": "application/json", "url": "http://localhost:59873/"}
}
...
_server.close();
sendHttpRequest(url, method, headers, data, callback)
Version added: 0.126
Permissions required: Web
Send an https request (of different methods) to localhost/127.0.0.1 while by-passing a valid certificate verification.
Parameter | Type | Description |
---|---|---|
url | string | |
method | HttpRequestMethods enum | |
headers | FetchHeader[] | an array of http headers (key,value) pairs. See notes below |
data | string (Optional) | The data being sent to the server (relevant for POST/PUT requests) |
callback | SendHttpRequestResult Object | Container for the send requests |
headers
notes
An example of FetchHeader objects array: [{ key: "Content-Type", value: "application/json" }]
.
createWebSocket(connectionParams, callback)
Version added: 0.129
Permissions required: Web
Creates a WebSocket client to localhost/127.0.0.1.
Parameter | Type | Description |
---|---|---|
connectionParams | WebSocketConnectionParams Object | connection params. See notes below |
callback | CreateWebSocketResult Object | A callback function which will be called with the status of the request |
connectionParams
notes
An example:
{
"secured":true,
"port": int,
"credentials": {
"username": "riot",
"password": "string" (e.g lcuCredentialsoverw.native_token)
},
"protocols":["wamp"]
}
WebSocketConnectionParams Object
Version added: 0.129
Container for the connection params.
Parameter | Type | Description |
---|---|---|
secured | bool | |
port | int | The port to use |
credentials | LoginCredentials | |
protocols | string[] |
HttpRequestMethods enum
Version added: 0.129
HTTP requests methods.
Option | Description |
---|---|
GET | |
HEAD | |
POST | |
PUT | |
DELETE | |
PATCH |
FetchHeader Object
Version added: 0.126
Container for a key value pair that represent an HTTP header.
Read more about http headers here.
Parameter | Type | Description |
---|---|---|
key | string | |
value | string |
Object Data Example
{ "key": "Content-Type", "value": "application/json" }
MessageType enum
Version added: 0.129
Describes different types on messages.
Option | Description |
---|---|
ping | |
binary | |
text |
Example data: Success
CreateServerResult Object
Parameter | Type | Description |
---|---|---|
success | boolean | inherited from the "Result" Object |
error | string | inherited from the "Result" Object |
server | WebServer object |
Example data: Success
A callback function which returns the status of the request and an object with two fields: A status string and a server object.
{
"status": "success",
"server": {
"onRequest": {}
}
}
SendHttpRequestResult Object
Parameter | Type | Description |
---|---|---|
success | boolean | inherited from the "Result" Object |
error | string | inherited from the "Result" Object |
statusCode | number | |
data | string |
Example data: Success
{ "status": "success" }
CreateWebSocketResult Object
Parameter | Type | Description |
---|---|---|
success | boolean | inherited from the "Result" Object |
error | string | inherited from the "Result" Object |
client | WebSocket object |
Example data: Success
This call returns a status and a WebSocket object.
{
"status": "success",
"client": "IOverwolfWebSocket"
}