meh
meh

Reputation: 273

apache nifi send message body with GET

i working on an API web service that needs message body on GET method to get results. on Apache Nifi I've been used InvokeHTTP processor (mostly POST) but in this situation Nifi did not sent message body on GET method (or DELETE, according its documentations). is there a way to do it?

Upvotes: 0

Views: 840

Answers (1)

daggett
daggett

Reputation: 28634

use ExecuteGroovyScript

@Grab(group='acme.groovy', module='acmehttp', version='20.04.27', transitive=false)
import groovyx.acme.net.AcmeHTTP

def ff=session.get()
if(!ff)return
def http
ff.write{ffIn, ffOut->
    http = AcmeHTTP.get(
        url:    "https://httpbin.org/post", //base url
        query: [aaa:"hello", bbb:"world!"], //query parameters
        // send flowfile content (stream) as a body
        body:   ffIn,
        headers:[
            //assign content-type from flowfile `mime.type` attribute
            "content-type":ff.'mime.type' 
        ],
        // the receiver that transfers url response stream to flowfile stream
        receiver:{respStream, ctx-> ffOut << respStream }
    )
}
//set response hesders as flow file attributes with 'http.header.' prefix
http.response.headers.each{ k,v-> ff['http.header.'+k]=v }
//status code and message as attributes
ff.'http.status.code' = http.response.code
ff.'http.status.message' = http.response.message
//transfer to success
REL_SUCCESS << ff

Upvotes: 1

Related Questions