Skip to content

AddParameter

Adds a new parameter to the request body.

1
myRestRequest.AddParameter(name: string, value: object):RestRequest

Adds a new parameter to the request body with a specified type.

1
myRestRequest.AddParameter(name: string, value: object, type?: ( `"Cookie"` | `"GetOrPost"` | `"UrlSegment"` | `"HttpHeader"` | `"RequestBody"` | `"QueryString"` | `"QueryStringWithoutEncode"` )):RestRequest

Parameters

string name
    The name of the parameter.

object value
    The value of the parameter.

( "Cookie" | "GetOrPost" | "UrlSegment" | "HttpHeader" | "RequestBody" | "QueryString" | "QueryStringWithoutEncode" ) type optional
    The type of the parameter. Optional.

Returns

The current RestRequest instance. The current RestRequest instance.

Remarks

The name and value arguments are required.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
var client = $Rest.Create('http://targetserver');
var request = client.Request();

request.AddParameter('x', 1);
request.AddParameter('y', {
  z : 3
});

// request body as
// {
//    "x" : 1,
//    "y" : {
//        "z" : 3
//    }
// }

var response = request.ExecuteJson();
The name and value arguments are required.

If the type parameter is not specified, the default value is "GetOrPost".

The type parameter can be one of the following:

  • Cookie
  • GetOrPost
  • UrlSegment
  • HttpHeader
  • RequestBody
  • QueryString
  • QueryStringWithoutEncode

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
var client = $Rest.Create('http://targetserver');
var request = client.Request();

request.AddParameter('x', 1);
request.AddParameter('y', {
  z : 3
});

// request body as
// {
//    "x" : 1,
//    "y" : {
//        "z" : 3
//    }
// }

var response = request.ExecuteJson();

See Also