# Class: modelit.web.client.HttpRequest

### Extends: modelit.web.concurrent.Callable & matlab.mixin.SetGet & handle

## DESCRIPTION:

Create an HttpRequest.

#

## Properties

body | uint8[]|int8[]|char[] |
      The payload.
      This is the actual message that is to be sent.
CompletedCallback | @(event) |
      Callback triggered when the request has finished sucessfully.
connecttimeout | integer default value 5000 |
      Milliseconds for connection timeout.
ExceptionOccurredCallback | @(obj, event) |
      Callback triggered when the request failed.
headers | cellstr with name-value pairs. |
      The request headers.
      See for example: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers
InitializedCallback | @(obj, event) |
      Callback triggered when the request is sent.
method | string |
      The http request method,
      See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
parameters | cellstr with name-value pairs. |
      The query parameters.
      See for example: https://en.wikipedia.org/wiki/Query_string
ProgressUpdatedCallback | @(obj, event) |
      Callback triggered when the server returns a progress update.
proxyAddress | string |
      The url of the proxyserver.
proxyPort | integer |
      The port of the proxy server.
timeout | integer default value: 5000 |
      Milliseconds for response timeout.
url | string |
      The destination url.

# Public Method: HttpRequest

## DESCRIPTION:

Create an HttpRequest.

## CALL:

obj = HttpRequest(method, url, varargin)

## INPUT:

method | string |
    The http method, e.g. 'POST', 'GET' or 'PUT'
    See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
url | string |
    The destination url.
varargin | (string,any)[] |
    Parameter-value pairs corresponding to the HttpRequest properties.

## OUTPUT:

obj | modelit.web.client.HttpRequest |
    Documentation for modelit.web.client.HttpRequest/HttpRequest
       doc modelit.web.client.HttpRequest

# Public Method: feval_async

## DESCRIPTION:

Evaluate a Matlab function remotely and asynchronously.

## CALL:

varargout = feval_async(obj, fp_final, fp, varargin)

## INPUT:

obj | modelit.web.client.HttpRequest |
fp_final | functionhandle |
    The function to be evaluated locally after the remote evaluation has finished.
fp | functionhandle |
    The function to be evaluated remotely.
varargin | any |
    The arguments.

## OUTPUT:

varargout | any |
    The outputs of the function evaluation.

## EXAMPLE:

       h = modelit.web.client.HttpRequest('GET','http://localhost:4444')

       disp(sprintf('%d',10)) % where "sprintf('%d',10)" is executed remotely
       feval_async(h,@disp,@sprintf,'%d',10)

# Public Method: feval

## DESCRIPTION:

Evaluate a Matlab function remotely.

## CALL:

varargout = feval(obj, fp, varargin)

## INPUT:

obj | modelit.web.client.HttpRequest |
fp | functionhandle |
    The function to be evaluated remotely.
varargin | any |
    The arguments.

## OUTPUT:

varargout | any |
    The outputs of the function evaluation.

## EXAMPLE:

       h = modelit.web.client.HttpRequest('GET','http://localhost:4444')
       [tf,f] = feval(h,@find,[false, true])

       N=0;
       for k=1:100,
       N = N+(feval(h,@randn,1)>0);
       end
       disp(N)

# Public Method: setCredentials

## DESCRIPTION:

Set username and password for authenticated request.

## CALL:

obj = setCredentials(obj, username, password)

## INPUT:

obj | modelit.web.client.HttpRequest |
username | string |
    The username.
password | string |
    The password.

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setTimeOut

## DESCRIPTION:

Set the milliseconds before a response timeout.

## CALL:

obj = setTimeOut(obj, timeout)

## INPUT:

obj | modelit.web.client.HttpRequest |
timeout | integer |
    Milliseconds before response timeout.

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setConnectTimeOut

## DESCRIPTION:

Set the milliseconds before a connection timeout.

## CALL:

obj = setConnectTimeOut(obj, timeout)

## INPUT:

obj | modelit.web.client.HttpRequest |
connecttimeout | integer |
    Milliseconds before failover due to connection timeout.

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setProxy

## DESCRIPTION:

Set the proxy address.

## CALL:

obj = setProxy(obj, proxyAddress, proxyPort))

## INPUT:

obj | modelit.web.client.HttpRequest |
proxyAddress | string |
    The proxy address.
proxyPort | integer |
    The proxy port.

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setMethod

## DESCRIPTION:

The http method, e.g. 'POST', 'GET' or 'PUT'

## CALL:

obj = setMethod(obj, method)

## INPUT:

obj | modelit.web.client.HttpRequest |
method | string |
    The http method, e.g. 'POST', 'GET' or 'PUT'
    See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: addParameters

## DESCRIPTION:

Add one or more query parameters.

## CALL:

obj = addParameters(obj, varargin)

## INPUT:

obj | modelit.web.client.HttpRequest |
varargin | string, string |
    parameter, value pairs. E.g. 'q', '1'

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setParameters

## DESCRIPTION:

Set the query parameters. The query parameters are attached to the end of a url after the '?'. E.g. https://www.google.com/search?q=abstract.

## CALL:

obj = setParameters(obj, parameters)

## INPUT:

obj | modelit.web.client.HttpRequest |
parameters | cellstring |
    name-value pairs with the query parameters.

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: addHeader

## DESCRIPTION:

Add one or more request headers.

## CALL:

obj = setUrl(obj, varargin)

## INPUT:

obj | modelit.web.client.HttpRequest |
varargin | string |
    header-value pairs, e.g. 'Content-Type', 'text/html'
    See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setHeaders

## DESCRIPTION:

Set the request headers. The HTTP headers can be used in an HTTP request to provide information about the request context.

## CALL:

obj = setUrl(obj, url)

## INPUT:

obj | modelit.web.client.HttpRequest |
headers | cell[] |
    The request headers in name-value pairs.
    See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setUrl

## DESCRIPTION:

Set the destination url.

## CALL:

obj = setUrl(obj, url)

## INPUT:

obj | modelit.web.client.HttpRequest |
url | string |
    The destination url. e.g. https://www.httpbin.org/get

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setBody

## DESCRIPTION:

Set the contents of the request Body. This is the actual data to be sent to the endpoint.

## CALL:

obj = setBody(obj, body)

## INPUT:

obj | modelit.web.client.HttpRequest |
body | int8[]|uint8[]|char[] |
    The data of the request body.

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Private Method: callback

## DESCRIPTION:

Evaluate the Completed callback.

## CALL:

callback(obj, event)

## INPUT:

obj | modelit.web.client.HttpRequest |
event | nl.modelit.web.client.CompletionEvent |

## OUTPUT:

          no output

# Private Method: addCallbacks

## DESCRIPTION:

Add the callbacks defined in the Matlab object to the java object.

## CALL:

obj = addCallbacks(obj)

## INPUT:

obj | modelit.web.client.HttpRequest |

## OUTPUT:

obj | modelit.web.client.HttpRequest |
    callbacks defined in the Matlab object are added to the
    java object.

# Public Method: getCallable

## DESCRIPTION:

Get the java object which extends the Callable interface.

## CALL:

callable = getCallable(obj)

## INPUT:

obj | modelit.web.client.HttpRequest |

## OUTPUT:

callable | modelit.web.concurrent.Callable |

# Public Method: setProgressUpdatedCallback

## DESCRIPTION:

Set the callback to be executed when the client has received the complete response from the server.

## CALL:

setProgressUpdatedCallback(obj, callback)

## INPUT:

obj | modelit.web.client.HttpRequest |
callback | @(obj, event) |
    Use event.getProgress to get the progress (values
    between 0 and 100).

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setExceptionOccurredCallback

## DESCRIPTION:

Set the callback to be executed when the server returns an error.

## CALL:

obj = setExceptionOccurredCallback(obj, callback)

## INPUT:

obj | modelit.web.client.HttpRequest |
callback | @(obj, event) |
    Callback executed when the server returns an error.

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setInitializedCallback

## DESCRIPTION:

Set the callback to be executed when the client starts sending the request.

## CALL:

obj = setInitializedCallback(obj, callback)

## INPUT:

obj | modelit.web.client.HttpRequest |
callback | @(obj, event) |
    Callback executed when the client start sending the
    request. This is useful in combination with the
    modelit.web.concurrent.ThreadPoolExecutor to detect when a submitted request is executed.

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: setCompletedCallback

## DESCRIPTION:

Set the callback to be executed when the client has received the complete response from the server.

## CALL:

obj = setCompletedCallback(obj, callback)

## INPUT:

obj | modelit.web.client.HttpRequest |
callback | @(obj) |
    Callback executed when the request has completed. i.e.
    the complete response has been received. obj is a
    modelit.web.client.HttpResponse

## OUTPUT:

obj | modelit.web.client.HttpRequest |

# Public Method: send

## DESCRIPTION:

Send the request. This method is asynchronous when a CompletedCallback is specified.

## CALL:

response = send(obj)

## INPUT:

obj | modelit.web.client.HttpRequest |

## OUTPUT:

response | [] | modelit.web.client.HttpResponse |

# Private Static Method: evaluationCallback

## DESCRIPTION:

Assert that no error occured on remote computer.