<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MM2 can get POST API?]]></title><description><![CDATA[<p dir="auto">I am developing a module of MM.<br />
By the way, I want to control one of these modules by an external client, and I want to do that control method by REST API method.<br />
For example, if an external client sends a POST API to MM2, the corresponding message is displayed on the MM2 screen.<br />
I don’t know because I haven’t read the MM2 code in detail, but as far as I’ve checked, the server also automatically turns on when running MM2, so I want to process REST API communication on that server as well, but which file should I modify and put a phrase related to REST API communication in order that?</p>
<p dir="auto">server.js?<br />
server_function.js?</p>
<p dir="auto">Examples of API codes that I want to put in are these.<br />
The API code is an API that stores the message as a txt file when a message is transmitted in a POST method.</p>
<pre><code>app.post('/api/saveMessage', (req, res) =&gt; {
    const message = req.body.message;

    if (!message) {
        res.status(400).send('Message not provided.');
        return;
    }

    fs.unlink(`appid.txt`, (err) =&gt; {
        fs.appendFile(`appid.txt`, message + '\n', (err) =&gt; {
            if (err) {
                console.error('Error saving message:', err);
                res.status(500).send('Error saving message');
            } else {
                res.send('The message was saved successfully..');
            }
        });
    });
});
</code></pre>
]]></description><link>https://forum.magicmirror.builders/topic/18145/mm2-can-get-post-api</link><generator>RSS for Node</generator><lastBuildDate>Thu, 21 May 2026 14:18:37 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/18145.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 04 Nov 2023 04:54:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MM2 can get POST API? on Sat, 04 Nov 2023 21:39:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hikano765" aria-label="Profile: hikano765">@<bdi>hikano765</bdi></a><br />
use <code>this.expressApp</code> in node_helper.js<br />
Of course, you can use your own <code>express</code> or <code>fastify</code> whatever by importing that node module.</p>
]]></description><link>https://forum.magicmirror.builders/post/112303</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/112303</guid><dc:creator><![CDATA[MMRIZE]]></dc:creator><pubDate>Sat, 04 Nov 2023 21:39:15 GMT</pubDate></item><item><title><![CDATA[Reply to MM2 can get POST API? on Sat, 04 Nov 2023 21:42:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hikano765" aria-label="Profile: hikano765">@<bdi>hikano765</bdi></a> you use express lib to set up a server.</p>
<p dir="auto">you can look at the node_helper in my mmm-config module, as I provide an API.</p>
<p dir="auto"><a href="https://github.com/sdetweil/MMM-Config" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/sdetweil/MMM-Config</a></p>
<p dir="auto">I redirect ,  but u can do whatever</p>
<pre><code>  // add express routes to allow invoking the form
  extraRoutes: function () {
    this.expressApp.get("/modules/MMM-Config/review", (req, res) =&gt; {
      // redirect to config form
      res.redirect(
        //this.config.url +
        "/modules/" + this.name + "/config.html?port=" + socket_io_port
      );
    });
  },
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/112302</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/112302</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Sat, 04 Nov 2023 21:42:50 GMT</pubDate></item></channel></rss>