Multiple path parameters on http in node for api

Possibly a silly question.

I am trying to write an api with the http in node. I want to use path parameters so that I can have an api path that is - for instance - in the form api/:color/:shape

Is it possible to have more than one path parameter on the http in node? I can do it with query parameters, but path would be nicer for others in the team.

When I try it, it's easy to do the api/:color part, but as soon as I try anything with a second path parameter I just get no response at all. And nothing even in the debug node in my node-red environment.

What am I missing??


Under the hood, this is just an express endpoint so api/:color/:shape should work - so long as the URL has both parts.
But if you want it shape to be optional (omitted from the URL), you need to add a question mark api/:color/:shape?

Note: this matcher api/:color/:shape? leaves little room for other more specific routes (basically it would intercept api/user/1 - clearly not intended.

I would recommend you at minimum specify a version and 1 fixed part to the path (to permit other future routes) e.g. api/v1/something/:color/:shape?

1 Like

Yeah - I thought it should be straightforward and indeed - all this is downstream of a v1/specificfunction/ path in the APIs.

So it's really /v1/checkshape/:color/:shape

But I still don't get it to work. All I'm doing is setting msg.payload to be msg.req.params and passing it back in the http response.

If I have one path, no problem at all. Soon as I add that second path? No response. Not even a debug message. I'm sending the messages from postman mostly, but I tried from command line (with Curl) as well.

Me be puzzled. I'm on 3.0.0.

If you are not getting anything, then maybe you have another route swallowing it. Try disabling other http-in nodes.

I don't understand why, but I added "2" to the rmain route, deployed, deleted the "2", deployed again, and now it works.

As I was editing previously it's possible that there had been another copy of the http-in node at one stage, but it hadn't existed for a while.

In any case, it all works fine now! As it should, it "just works".



1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.