Node red with microservices

Hello,
I would like to do following example:
I would like to have my own microservice - for example - /weater?location=? (and how can I do that "?" would be changed to wanted location in node red?) - then in other node - there should be http request, which should send request to some working API with
location from the url (location=?) - this API should send back JSON with information - I want these information send back to client who used my microservice.

  1. Is my flow ok? Should it work?
    2.I have microservice - /weater?location=? - ? should be always replaced with a location in that url. How can I do that?
  2. In http request I have:
    https://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22
    Again, I need to replace "q=London" with something like "q=?" and "?" should be replaced with location in previous url
  3. If request is successfuly sent, client should receive answer (json) in http response, am I right?

V%C3%BDst%C5%99i%C5%BEek

Thank you for you help

If you start with a http-in you need to end your flow with an http-out

You will also need to have some logic & reformating between your http-in and your http request nodes.

Try looking at the function node.
Each node in the info panel on the right hand side should explain what part of the message object key bits of information should go in.

There are also examples of using http nodes in the cookbook at cookbook.nodered.org

Thank you for your reply.
I progressed a little bit:
First picture: Flow
So when I go to localhost:1880/weater/London - then I get JSON {"q": "London"} in msg.req.params;
Second picture: My function
Just setting msg.payload with msq.req.parameters (because I thought msg.payload could be used for parameters in my final url)
Third picture:
Thre is option to use msg.payload as parameters - Does not work for me. I deleted from my api: q=London and tried to check "use msg.payload as parameters" - but it does not work.
V%C3%BDst%C5%99i%C5%BEek V%C3%BDst%C5%99i%C5%BEek2 !

So, how can I set q=Location from my msg.payload to my final api URL?

Thanks

Third picture:

Ok, i figured it out. The problem was that I wrote localhost:1880/London - but api needs /London,uk - so it works as expected.

But I tried out to use google places (I downloaded it to node-red) and I have again very similiar problem with it...
So in google-places node, there is NOT option to put msg.payload as parameters. How can I insert parameters from msg.payload to google-places node?
Thank you again

It’s useful if you include the full name of the node that you have installed.
Assuming it is https://flows.nodered.org/node/node-red-node-google
The ReadMe includes full details of where in the msg object you need to include the data

Yes, when I write for example msg.location.lat (for example) in the function before google-places node - it says - lat is undefined. I also tried to return new msg object with location, lat, lon, radius, keyword etc in that function, but then it writes - no response object... and in google place node you can write parameters directly, but thats something I dont want to do...

The read the logging events section on the function docs and use it to check what you are actually doing inside your function node

https://nodered.org/docs/writing-functions#logging-events

Alternatively if you think it is a bug, as it is a contrib node follow the link from the nodes page in flows.nodered.org to the github page of the node where you can open an issue with the nodes author

I do not think, It is a bug - I would say problem is on my side.

I found out that I am getting JSON data back from google api - so i can read it in debugger, but http response node writes "no response object"... Any idea what might be wrong?
Google place node is attached to debugger (works fine) and to http response node - does not work fine...

Are you making sure that you pass the message received in the http request node on to the http response, and not removing response data (msg.res) in that message?

Yes, thank you!! I was creating a new msg object in the function and I did not specify this variable!

Thank you, it works fine now :slight_smile:

1 Like

Glad it is working. In function nodes it is generally best to modify the existing message and pass it on rather than make a new one, unless there are special requirements that force that.