Reputation: 11
How to do two post request together in krakend sequentially and pass output of one post request to the body of 2nd post request in krakend this is my krakend.json code.
{
"@comment": "//Comment : Create a new post and pass the post Id to create new comment.",
"endpoint": "/v1/createPostAndComments",
"method": "GET",
"input_query_strings": [],
"input_headers": [
"*"
],
"output_encoding": "json",
"backend": [
{
"url_pattern": "/posts",
"method": "POST",
"extra_config": {
"modifier/body-generator": {
"path": "./template/body.json.tmpl",
"content_type": "application/json",
"debug": true
}
},
"host": [
"https://jsonplaceholder.typicode.com"
],
"group": "backend0",
"allow": [ "id" ],
"mapping": {
"id": "details",
"resp_data":"fOne"
},
"encoding": "json",
"sd": "static"
},
{
"url_pattern": "/comments",
"encoding": "json",
"sd": "static",
"method": "POST",
"extra_config": {
"modifier/body-generator": {
"template": "{{ '{\"postId\": \"{{ resp0_id }}\", \"name\": \"{{ .req_body.name }}\", \"email\": \"{{ .req_body.email }}\", \"body\": \"{{ .req_body.body }}\"}' | b64enc }}",
"content_type": "application/json",
"debug": true
}
},
"mapping": {
"details": "opOne",
"postId": "opTwo",
"resp_data":"ftwo",
"resp0_":"fonetr",
"resp1_":"ftwotr"
},
"group": "backend1",
"host": [
"https://jsonplaceholder.typicode.com"
],
"disable_host_sanitize": false
}
],
"extra_config": {
"proxy": {
"sequential": true
}
}
}
and this here in this line "template": "{{ '{"postId": "{{ resp0_id }}", "name": "{{ .req_body.name }}", "email": "{{ .req_body.email }}", "body": "{{ .req_body.body }}"}' | b64enc }}", and i am not able to get resp0_id value from the response of 1st api , i am new to krakend any help/documents is really appriciated
I tried body modifier with template and passing required data to the body of 2nd api as resp0_.id but it is not working.
Upvotes: -1
Views: 857
Reputation: 1440
If you are new to KrakenD, and you are asking this here is probably because you haven't realized that what you are trying to do with modifier/body-generator
is actually an Enterprise feature that is ignored on Community edition. If you are an Enterprise customer, then you don't need to ask here as they have a dedicated team for this where you can ask 24/7.
Upvotes: 0