इस उदाहरण में, Assign Message की तीन नीतियों का इस्तेमाल किया गया है:

  1. यह अनुरोध में तीन फ़्लो वैरिएबल बनाता है. इनकी वैल्यू स्टैटिक होती हैं
  2. अनुरोध फ़्लो में दूसरी नीति में फ़्लो वैरिएबल को डाइनैमिक तरीके से सेट करता है
  3. यह कुकी, उन्हें जवाब के पेलोड में सेट करती है
<!-- Policy #1: Set variables in the request -->

<AssignMessage name="AM-set-variables">
    <!-- Create a variable named myAppSecret -->
    <AssignVariable>
        <Name>myAppSecret</Name>
        <Value>42</Value>
    </AssignVariable>
    <!-- Create a variable named config.environment -->
    <AssignVariable>
        <Name>config.environment</Name>
        <Value>test</Value>
    </AssignVariable>
    <!-- Create a variable named config.protocol -->
    <AssignVariable>
        <Name>config.protocol</Name>
        <Value>gopher</Value>
    </AssignVariable>
</AssignMessage>

पहली नीति में, <AssignVariable> एलिमेंट, अनुरोध में तीन वैरिएबल बनाता है और उन्हें सेट करता है. हर <Name> एलिमेंट, वैरिएबल का नाम तय करता है. वहीं, <Value> वैल्यू तय करता है.

दूसरी नीति, वैल्यू को पढ़ने के लिए <AssignVariable> एलिमेंट का इस्तेमाल करती है. साथ ही, तीन नए वैरिएबल बनाती है:

<!-- Policy #2: Get variables from the request -->
<AssignMessage continueOnError="false" enabled="true" name="get-variables">
  <AssignTo createNew="false" transport="http" type="request"/>
  <!-- Get the value of myAppSecret and create a new variable, secret -->
  <AssignVariable>
    <Name>secret</Name>
    <Ref>myAppSecret</Ref>
    <Value>0</Value>
  </AssignVariable>
  <!-- Get the value of config.environment and create a new variable, environment -->
  <AssignVariable>
    <Name>environment</Name>
    <Ref>config.environment</Ref>
    <Value>default</Value>
  </AssignVariable>
  <!-- Get the value of config.protocol and create a new variable, protocol -->
  <AssignVariable>
    <Name>protocol</Name>
    <Ref>config.protocol</Ref>
    <Value>default</Value>
  </AssignVariable>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

दूसरी नीति में, <Ref> एलिमेंट, सोर्स वैरिएबल का रेफ़रंस देता है. साथ ही, <Name> एलिमेंट, नए वैरिएबल के नाम तय करते हैं. अगर <Ref> एलिमेंट से रेफ़र किया गया वैरिएबल ऐक्सेस नहीं किया जा सकता, तो <Value> एलिमेंट से तय की गई वैल्यू का इस्तेमाल किया जा सकता है.

नीतियों के इस सेट को आज़माने के लिए:

  1. अनुरोध फ़्लो में नीतियां #1 और #2 जोड़ें. नीति #1 को नीति #2 से पहले रखना न भूलें.
  2. जवाब के फ़्लो में तीसरी नीति जोड़ें.
  3. तीसरी नीति में, जवाब में वैरिएबल जोड़ने के लिए <Set> एलिमेंट का इस्तेमाल किया गया है. यहां दिए गए उदाहरण में, रिस्पॉन्स में एक एक्सएमएल पेलोड बनाया गया है. यह पेलोड, Edge क्लाइंट को वापस भेजता है:
    <!-- Policy #3: Add variables to the response -->
    <AssignMessage continueOnError="false" enabled="true" name="put-em-in-the-payload">
      <DisplayName>put-em-in-the-payload</DisplayName>
      <Set>
        <Payload contentType="application/xml">
          <wrapper>
            <secret>{secret}</secret>
            <config>
              <environment>{environment}</environment>
              <protocol>{protocol}</protocol>
            </config>
          </wrapper>
        </Payload>
      </Set>
      <IgnoreUnresolvedVariables>true
      </IgnoreUnresolvedVariables>
      <AssignTo createNew="false" transport="http" type="response"/>
    </AssignMessage>

    ध्यान दें कि <Set> में फ़्लो वैरिएबल को ऐक्सेस करने का सिंटैक्स, उन्हें कर्ली ब्रैकेट में रैप करना है.

    <Payload> एलिमेंट के contentType एट्रिब्यूट को "application/xml" पर सेट करना न भूलें.

  4. अपनी एपीआई प्रॉक्सी को एक अनुरोध भेजें. उदाहरण के लिए:
    curl -vL https://ahamilton-eval-test.apigee.net/myproxy

    इसके अलावा, नतीजों को xmllint जैसे किसी यूटिलिटी के ज़रिए पाइप किया जा सकता है, ताकि एक्सएमएल को अच्छी तरह से फ़ॉर्मैट किए गए स्ट्रक्चर में दिखाया जा सके:

    curl -vL https://ahamilton-eval-test.apigee.net/myproxy | xmllint --format -

    जवाब का मुख्य हिस्सा कुछ ऐसा दिखना चाहिए:

    <wrapper>
      <secret>42</secret>
      <config>
        <environment>test</environment>
        <protocol>gopher</protocol>
      </config>
    </wrapper>