In NiFi processor 'InvokeHTTP' where do you write body of POST request?
Asked Answered
P

2

8

Before posting this question about Apache NiFi InvokeHTTP I have gone through all other questions and their answersbut I am still unsure the best flow I should have. My situation is as below:

1) From Apache Kakfa, I get raw metadata.

2) Using EvaluateJSONPath I get attribute I want.

3) Using RouteOnAttribute I created 3 routes based on the attribute value I got from step-2 above.

4) Now based on the attribute value I want to decide whether I should go for GET or for POST or for Delete.

5) My question is where/how to set POST message? GET message? Delete Message body?

6) I am able to set the URL in configuration part provided by InvokeHTTP. But message body I don't know which is that property? or its in flow file using ReplaceText?

I read somewhere that before you divert your Restful POST HTTP request to InvokeHTTP you must have another processor before which changes the content of flow file.

Ref: Configuring HTTP POST request from Nifi

Please help. Thanks. regards, Yeshwant

Penalty answered 18/12, 2018 at 11:2 Comment(1)
that's right - the flow file content will go into http request body. so, you could use ReplaceText or other content changing processors before InvokeHTTP to set request bodyTwelvemo
C
9

Adding on to what Bryan had explained, POST will use the FlowFile content as the message body so if you have some other data which you want to wipe/transform into something and then sent as the message body, you can leverage the following processors :

  • ExtractText to read data from the existing FlowFile content
  • ReplaceText to erase the existing content of the FlowFile and replace it with different one

To set the headers for the REST calls, InvokeHTTP has the property Attributes to Send property which takes a regex which will scanned against the incoming FlowFiles' attributes and whichever attributes are matched are taken and sent as HTTP header.

To add new attribute to your existing FlowFile, you can use UpdateAttribute

Carsoncarstensz answered 19/12, 2018 at 6:14 Comment(0)
E
8

For a POST, the body will be whatever is in the flow file content.

a GET and DELETE typically wouldn't have a body since the information would typically be provided in the URL or query params.

Electrotype answered 18/12, 2018 at 14:55 Comment(3)
Thanks Bryan. Can you tell me in configuration: 1) What should be the value of the property for field content type for GET, POST, PUT and DELETE? I set to ${mime.type}? 2) What should be the value of "Attributes to send"? If you read following link someone has said value of 'Attributes to send' should be - content-type=application/json community.hortonworks.com/questions/55615/…Penalty
You need to find out what the web-service you are interacting with accepts for those operations. For a request that doesn't have a body like a GET or DELETE, then content type doesn't really matter. For a POST or PUT, if the web service accepts JSON then it should be application/json, assuming you have json in the body of the flow file.Electrotype
I would pretend you weren't using NiFi and then think about what would you send for content-type if you were using Curl or Postman or some other tool to make the calls. Whatever values you use from the other tool would be the same from NiFi.Electrotype

© 2022 - 2024 — McMap. All rights reserved.