Http request node; Send payload as part of the request body when using GET in subflow

Hello,

Depending on what I need from the endpoint I'm calling, I need to be able to send the payload as the request body using both GET & POST.

I'm creating a query to OpenSearch, sending the payload using a GET method, which uses OpenSearch's built-in cache, and sending the payload using the POST method; no caching is used on the OpenSearch side.

Sending the payload using the POST method works as expected; however, I have problems under GET.

If I set the method to GET in the editor, set the payload to;

  • Ignore
  • Append to query-string parameters.
  • Send as request body

I can set the payload option to Send as request body.
Choosing this option works as expected.

Screenshot 2024-08-30 at 2.38.42 PM

However;

I have created a subflow with the HTTP request method set to - set by msg.method

I don't have a payload option, and I understand why as the method is not know yet.

If I have the same JSON in the msg.payload, it is not sent to the endpoint; it is ignored by default.

The info for the HTTP request node states

payload
Sent as the body of the request.

How do I get the msg.payload to send as request body when method is being set by the msg.method?

Thanks
Harry

I feel like I should be able to bend spoons by looking at them when I hear GET and Body in the same sentence.

But in actural fact, there is no rule to state a body should not be included in GET

RFC 7231

   A payload within a GET request message has no defined semantics;
   sending a payload body on a GET request might cause some existing
   implementations to reject the request.

So whilst not normal, is not illegal

Doing a test - it would "seem" a body is not included in GET in the request node

Insurance Document : Unless the HTTP IN node ignores them in my test (again not illegal) :man_shrugging:

Interesting discussion point.

@Steve-Mcl @knolleary

What the opinion here?
if using msg.method - one should still allow to include a body and decide how it should be treated?

it feels like if using method='GET' payload is ignored? (as a body at least)

@HarryPottar
Can you include a test flow, that demos this? im sure you can magic one up :wink:

1 Like

I am pretty sure I handled this in this PR: Add msg property `payloadHandling` for setting how a GET request handles payload by Steve-Mcl · Pull Request #3961 · node-red/node-red · GitHub

But as yet it is not merged.

2 Likes

You did!

As reported on forum and raised in #3957, the HTTP Request node could not set the payload handling for a get request.
The option set in the dropdown field before the method was changed to "use msg.method" and hidden would be used causing confusion to user.

:pray:

Oh Dang!!! - I was the one who raised it :rofl:

1 Like

Thank you so much. I spent too many hours on this today, looking down rabbit holes.

Of course, you are correct;

  1. Set the method to "GET"
  2. Configure the payload to be "Send as request body"
  3. Set the method to "- set by msg.method"

The payload setting is remembered, and the payload is sent as the body.

It just goes to show that you learn something new every day.

Once again, thank you for the quick response.

Harry

1 Like

Yup - this is what the PR aims to fix.

Either

  • Keep the handling option available
  • Use a new property to set it dynamically

I have not looked at the PR in detail

1 Like

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