Recombee API client

Batch extends Request

In many cases, it may be desirable to execute multiple requests at once. For example, when synchronizing the catalog of items in a periodical manner, you would have to execute a sequence of thousands of separate POST requests, which is very ineffective and may take a very long time to complete. Most notably, network latencies can make execution of such a sequence very slow and even if executed in multiple parallel threads, there will still be unreasonable overhead caused by the HTTP(s). To avoid the problems mentioned, batch processing may be used, encapsulating a sequence of requests into a single HTTP request.

Batch processing allows you to submit arbitrary sequence of requests in form of JSON array. Any type of request from the above documentation may be used in the batch, and the batch may combine different types of requests arbitrarily as well. Note that:

  • executing the requests in a batch is equivalent as if they were executed one-by-one individually; there are, however, many optimizations to make batch execution as fast as possible,
  • the status code of the batch request itself is 200 even if the individual requests result in error – you have to inspect the code values in the resulting array,
  • if the status code of the whole batch is not 200, then there is an error in the batch request itself; in such a case, the error message returned should help you to resolve the problem,

Table of Contents

$requests  : array<string|int, Request>
$ensure_https  : bool
$timeout  : int
__construct()  : mixed
Construct the Batch request
getBodyParameters()  : array<string|int, mixed>
Get body parameters
getEnsureHttps()  : bool
Returns true if HTTPS must be chosen over HTTP for this request
getMethod()  : static
Get used HTTP method
getPath()  : string
Get URI to the endpoint
getQueryParameters()  : array<string|int, mixed>
Get query parameters
getTimeout()  : int
Get request timeout
setEnsureHttps()  : mixed
Sets if HTTPS must be chosen over HTTP for this request
setTimeout()  : mixed
Sets request timeout
requestToBatchArray()  : mixed

Properties

$ensure_https

protected bool $ensure_https

Methods

__construct()

Construct the Batch request

public __construct(array<string|int, Request$requests[, array<string|int, mixed> $optional = array() ]) : mixed
Parameters
$requests : array<string|int, Request>

Array of Requests.

$optional : array<string|int, mixed> = array()

Optional parameters given as an array containing pairs name of the parameter => value

  • Allowed parameters:
    • distinctRecomms
      • Type: bool
      • Description: Makes all the recommended items for a certain user distinct among multiple recommendation requests in the batch.
Tags
throws
UnknownOptionalParameterException

UnknownOptionalParameterException if an unknown optional parameter is given in $optional

Return values
mixed

getBodyParameters()

Get body parameters

public getBodyParameters() : array<string|int, mixed>
Return values
array<string|int, mixed>

Values of body parameters (name of parameter => value of the parameter)

getEnsureHttps()

Returns true if HTTPS must be chosen over HTTP for this request

public getEnsureHttps() : bool
Return values
bool

true if HTTPS must be chosen

getMethod()

Get used HTTP method

public getMethod() : static
Return values
static

Used HTTP method

getPath()

Get URI to the endpoint

public getPath() : string
Return values
string

URI to the endpoint

getQueryParameters()

Get query parameters

public getQueryParameters() : array<string|int, mixed>
Return values
array<string|int, mixed>

Values of query parameters (name of parameter => value of the parameter)

getTimeout()

Get request timeout

public getTimeout() : int
Return values
int

Request timeout in milliseconds

setEnsureHttps()

Sets if HTTPS must be chosen over HTTP for this request

public setEnsureHttps(mixed $ensure_https) : mixed
Parameters
$ensure_https : mixed
Return values
mixed

setTimeout()

Sets request timeout

public setTimeout(mixed $timeout) : mixed
Parameters
$timeout : mixed
Return values
mixed

requestToBatchArray()

protected requestToBatchArray(mixed $req) : mixed
Parameters
$req : mixed
Return values
mixed

Search results