How to create a REST endpoint in NR reachable from outside CORE

Dear @RRodman @april.brandt @markus … I would like to test my generic rest server .
How can I PUT some content to a NR implemented endpoint ?
Have I to use an “http in” node ? Which is the url to reach my core NR (that is which ip and port I have to send the data to, being core a container?)

What I have done:
I wrote a simple rest manager in python.
I changed oll-node-red.conf file adding:

PORT MAP+=(“192.168.xxx.yyy:9000:1880”)

where 192.168.xxx.yyy is my core IP and 1880 should be the port of "HTTP in’ node in NR, if I’m not wrong

I created a flow with an HTTP in node method=GET and url=/put.
I send my REST commands to ‘http://192.168.xxx.yyy:9000//put
I get the following response:

<ClientResponse(http://192.168.xxx.yyy:9000//put) [404 Not Found]>
<CIMultiDictProxy(‘Content-Security-Policy’: “default-src ‘none’”, ‘X-Content-Type-Options’: ‘nosniff’, ‘Content-Type’: ‘text/html; charset=utf-8’, ‘Content-Length’: ‘143’, ‘Date’: ‘Fri, 27 Oct 2023 12:03:35 GMT’, ‘Connection’: ‘keep-alive’, ‘Keep-Alive’: ‘timeout=5’)>

Where I’m wrong?

Despite the docs and examples, I solved it:

the NR Http-in node must match the invoked method: if I am calling a PUT, the node has to declare method=PUT (instead of GET). Trivial but time wasting!
Of course should you want to query the NR node, the method must be GET.
The other settings (port mapping) are ok.

To test, I used a curl format allowing the Http-in node to receive a json structure to be used directly inside a nodered message (remember web browser allows only GET commands to be issued; if you want send a PUT command, you must use curl or similar):

curl -X PUT -H "Content-Type: application/json" -d " {\"sender_id\":\"1\",\"sender_name\":\"SW_STANZINO\"}" http://192.168.xxx.yyy:9000/pods/direct/node-red/put

Have a look to the following link (be warned it Is an example of a GET implementation)

https://cookbook.nodered.org/http/

3 Likes

My aopologies, I was out at work all day today. I’m Happy you solved it. Would make a great write up.

This topic was automatically closed after 180 days. New replies are no longer allowed.