javascript - Apigee policy mediation - assign message / extract variables -


i exposing json on rest interface via apigee edge.

externally, api consumers see following api spec:

i.e. creating customer.

post /customers?api_key=abc123 {    "name": "john",    "surname": "smith" }  

i have applied following policies: 1. verify api key 2. remove api key

i wondering how may able use extract / assign message policy achieve following "reconstructed" request payload when calling downstream system.

post /downstream-customer-service {    "correlationid": "<generated guid>",    "data": {       "name": "john",       "surname": "smith"          } } 

so, need to: 1. move original request body, , add "data" element 2. generate guid , assign "correlationid"

i assume need javascript policy? or achieved within javascript policy?

thank in advance.

i used javascript policy, , applied target endpoint preflow:

var = (function() {     self.generateuuid = function(a) {         // uuid4 generation: https://gist.github.com/jed/982883         return a?(a^math.random()*16>>a/4).tostring(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,self.generateuuid);     },     self.modifypayload = function(data, generatecorrelationid) {         var newpayload = {             "data": data         };          if(generatecorrelationid)             newpayload["correlationid"] = self.generateuuid();          return newpayload;      }     return self; })();  var modifieddata = this.modifypayload(context.targetrequest.body.asjson); context.setvariable("context.targetrequest.body", modifieddata); 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -