Do HTTP requests triggered by notifications from the MagicMirror Server.
This module use the Browser Fetch API on the node.js backend to do the actual http requests. The node-fetch packages is used to port the Fetch API to node.js.
This module does not provide any visual component, it's only an utility used by other modules via the notification mechanism of MagicMirror.
this.sendNotification("MMM-HTTP-Client-REQUEST", {
url: "https://example.com/api/webhook",
options: {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ data: 17 })
}
});
Because the fetch()
is executed on the node.js server, there are less restrictions on the requests you can do.
You don't have to care about Cross-Origin, Content Security Policy and Mixed Content.
But there are also downsides and limitations.
You can read more about them in the node-fetch docs.
cd modules
git clone https://github.com/Legion2/MMM-HTTP-Client.git
cd MMM-HTTP-Client
npm install
To use this module, add the following configuration block to the modules array in the config/config.js
file:
var config = {
modules: [
{
module: "MMM-HTTP-Client"
}
]
}
Notification | Payload | Description |
---|---|---|
MMM-HTTP-Client-REQUEST |
object | Do a http request from the node.js server. The payload is the request object, which must define the url of the request and can also define an optional options object for the fetch() call, see init parameter. |