Class: DataRequest

(package) nationscript/requests/base~DataRequest()

Superclass for all request subclasses that send data to the NS API.

Opens up methods to actually alter the request body, namely:

  • setArgument
  • setArguments
  • getArgument
  • getArguments
  • removeArguments

Via the mandate method, specific arguments can be declared mandatory, and NationScript will not execute requests that do not have values for the mandatory arguments in their body.

Lastly, it holds the user-configurable version property, which is used to request API responses in specific versions of the NS API to ensure compatibility with the hard-coded types.

Constructor

(package) new DataRequest()

Instantiates a new DataRequest, defining the Content-Type in the headers and setting the version, if required.

Members

(package, nullable) version :number

Defines the version of the NS API to request all data in. If null, requests are made to the most recent version of the API automatically.

Type:
  • number

Methods

getArgument(key) → {string}

Get the value that is currently saved in this request's body under the given key.

Parameters:
Name Type Description
key string

Name of the argument

Returns:

Data currently saved for that argument

Type
string

getArguments() → {Array.<string>}

Get the keys of all values that are currently set in the request body.

Returns:

List of all keys currently set

Type
Array.<string>

(protected) mandate(…names) → {this}

Registers the given parameter names as required to have a value set for them in the data before executing the request.

Parameters:
Name Type Attributes Description
names string <repeatable>

Names of the URL parameters to mandate

Returns:

The request, for chaining

Type
this

(async) raw()

removeArgument(key) → {this}

Remove the value saved under the given key in the request body.

Parameters:
Name Type Description
key string

Name of the key

Returns:

The request, for chaining

Type
this

setArgument(key, …values) → {this}

Set the given value under the given argument name in the request body.

Parameters:
Name Type Attributes Description
key string

Key to save the value under

values Array.<any> <repeatable>

Value(s) to save; joined with + if an array

Returns:

The request, for chaining

Type
this

setArguments(pairs, replace) → {this}

Set all the given keys and values in the request body.

Parameters:
Name Type Default Description
pairs Object.<string, string>

Key-value pairs of arguments

replace boolean false

true to replace all current arguments, false to merely add them to the extant arguments (default)

Returns:

The request, for chaining

Type
this