Skip to content

Request Call Repository

cjayswal edited this page Mar 3, 2018 · 5 revisions

Request call repository holds request calls in form of properties. It is a properties file to store request call.

Request call Fields

The request call is json map supporting following fields.

Field Required possible value description
baseUrl Required Web service base url default is env.baseurl
endpoint Optional service endpoint specify service end-point
headers Optional json map of key-val pair specify header to set in request
method Required GET/POST/PUT/DELETE Request method default is GET
query-parameters Optional json map of key-val pair specify query parameter to set in request
form-parameters Optional json map of key-val pair specify form parameter to set in request
body Optional request body specify request body to set in request
response-schema Optional json schema provide schema for response schema validation (support json response only)
reference Optional reference request call another request call from which this request call to be derived (since 2.1.13)
parameters Optional json map of key-val pair default values for the parameters to be used to resolve parameters in request call body, form-parameters, headers, or query parameters (since 2.1.13)

Request call in XML file

Example request call in xml file:

<my>
  <sample>
    <req>
    {
     'endPoint':'/myservice-endpoint',
     'headers':{
          'Content-Type': 'application/xml'
          },
     'body':'file:resources/data/reqbody.xml'
    }
    </req>
  </sample>
</my>

You also can specify each request field as XML node. For example:

<my>
  <sample>
    <reqwithbody1>
       <endPoint>/myservice-endpoint</endPoint>
       <headers>{'Content-Type': 'application/xml'}
      </headers>
      <body>file:resources/data/reqbody.xml</body>
    </reqwithbody1>
    <!-- using CDATA to provide inline xml body-->
    <reqwithbody2>
       <endPoint>/myservice-endpoint</endPoint>
       <headers>{'Content-Type': 'application/xml'}</headers>
      <body>
          <![CDATA[
            <message> here is xml body!... </message>
          ]]>
      </body>
    </reqwithbody2>

  </sample>
</my>

Request call in properties file

my.sample.req={'baseUrl':'${env.baseurl}','endPoint':'/myservice-endpoint','method':'POST','headers':{'Content-Type': 'application/xml'},'body':'file:resources/data/soapEnv1.xml'}

my.sample.req={'baseUrl':'${env.baseurl}','endPoint':'/myservice-endpoint','method':'GET','headers':{},'query-parameters':{'param1':'val1','param2':'val2'},'form-parameters':{},'body':''}

It is equivalent to

my.sample.req={'endPoint':'/myservice-endpoint','query-parameters':{'param1':'val1','param2':'val2'}}

Request body in separate file:

You can have request body in separate file. To provide file provide value as file:<filepath>.

my.sample.req={'baseUrl':'${env.baseurl}','method':'POST','body':'file:resources/data/reqbody_1.xml','parameters':{'val1':'abc','val2':'xyz'}}

Parameterized request call

<my>
  <sample>
    <req2>
       <endPoint>/myservice-endpoint</endPoint>
       <query-parameters>
       {
       'param1':'${param1}',
       'param2':'${param2}'
       }
      </query-parameters>
      <body><![CDATA[
      <message>${param3}</message>
   ]] ></body>
    </req2>
  </sample>
</my>

setting default values of parameters

Here is the example that demonstrates parameters in request call, default values for parameters, request call reference and overriding parameter values for reference.

<my>
  <sample>
    <req3>
       <endPoint>/myservice-endpoint</endPoint>
       <query-parameters>
       {
       'param1':'${param1}',
       'param2':'${param2}'
       }
      </query-parameters>
      <body><![CDATA[
      <message>${param3}</message>
      ]] >
      </body>
      <parameters>
        {
        'param1':'value1',
        'param2':'value3',
        'param3':'value3'
        }
      </parameters>
    </req3>
  </sample>
</my>

Reference example

<my>
  <sample>
    <req4>
       <endPoint>/myservice-endpoint</endPoint>
       <query-parameters>
       {
       'param1':'${param1}',
       'param2':'${param2}'
       }
      </query-parameters>
      <body><![CDATA[
      <message>${param3}</message>
      ]] >
      </body>
      <parameters>
        {
        'param1':'value1',
        'param2':'value3',
        'param3':'value3'
        }
      </parameters>
    </req4>

    <req5>
      <reference>my.sample.req3</reference>
      <parameters>
        {
        'param1':'newvalue1',
        'param2':''
        }
      </parameters>
    </req5>
  </sample>
</my>
my.sample.req6={'headers':{},'endPoint':'/myservice-endpoint','baseUrl':'${env.baseurl}','method':'POST','query-parameters':{'param1':'${val1}','param2':'${val2}'},'form-parameters':{'a':'b','i':10},'parameters':{'val1':'abc','val2':'xyz'}}

my.sample.req7={'reference':'my.sample.req6','parameters':{'val1':'abc123','val3':'xyz123'}}

Parameter Resolution

Priority for resolver is:

  1. data provided in argument while doing request (highest)
  2. parameter in request call
  3. parameter in request reference
  4. configuration property (lowest)