OptionsRequest
Overview
The OptionsRequest
class is used to perform HTTP OPTIONS requests, allowing developers to interact with APIs to determine supported operations on a resource. It supports synchronous and asynchronous request execution with various authentication methods, providing flexibility for different use cases.
Headers can be added to requests using the addHeader(headerName, value)
method, while the executeRequest()
and executeAsyncRequest()
methods handle synchronous and asynchronous execution, respectively. Asynchronous methods include callbacks for success and error handling, ensuring robust response management. Authentication options, including Windows authentication, are also supported.
Additional functionality includes retrieving allowed HTTP methods using getAllowedMethods(res)
and configuring preemptive authentication with usePreemptiveAuthentication(b)
. These features enable efficient API interaction and streamlined HTTP request handling.
For an overview of the HTTP client functionality and configuration options, refer to the HTTP Client and HTTP Client Config documentation.
Methods Summarized
Add a header to the request.
void
Execute the request method asynchronous.
void
Execute the request method asynchronous using windows authentication.
void
Execute the request method asynchronous.
void
Execute the request method asynchronous using windows authentication.
void
Execute the request method asynchronous.
void
Execute the request method asynchronous using windows authentication.
Execute the request method.
Execute the request method.
Execute a request method using windows authentication.
Returns the supported HTTP Request operations as a String Array
void
Whatever to use preemptive authentication (sending the credentials in the header, avoiding the server request to the client - useful when uploading files, as some http servers would cancel the first request from the client, if too big, as the authentication request to the client was not yet sent)
Methods Detailed
addHeader(headerName, value)
Add a header to the request.
Parameters
Returns: Boolean
Sample
executeAsyncRequest(username, password, workstation, domain, successCallbackMethod, errorCallbackMethod)
Execute the request method asynchronous. Success callback method will be called when response is received. Response is sent as parameter in callback. This Response can be a response with a different status code then just 200, it could also be 500, which is still a valid response from the server, this won't go into the error callback. So you need to test the Reponse.getStatusCode() for that to know if everything did go OK. If no response is received (request errors out), the errorCallbackMethod is called with exception message as parameter.
Parameters
String username the user name
String password the password
String workstation The workstation the authentication request is originating from.
String domain The domain to authenticate within.
Function successCallbackMethod callbackMethod to be called after response is received
Function errorCallbackMethod callbackMethod to be called if request errors out
Returns: void
Sample
executeAsyncRequest(username, password, workstation, domain, successCallbackMethod, errorCallbackMethod, callbackExtraArgs)
Execute the request method asynchronous using windows authentication. Success callback method will be called when response is received. Response is sent as parameter in callback followed by any 'callbackExtraArgs' that were given. This Response can be a response with a different status code then just 200, it could also be 500, which is still a valid response from the server, this won't go into the error callback. So you need to test the Reponse.getStatusCode() for that to know if everything did go OK. If no response is received (request errors out, network errors), the errorCallbackMethod is called with exception message as parameter followed by any 'callbackExtraArgs' that were given.
Parameters
String username the user name
String password the password
String workstation The workstation the authentication request is originating from.
String domain The domain to authenticate within.
Function successCallbackMethod callbackMethod to be called after response is received
Function errorCallbackMethod callbackMethod to be called if request errors out
Array callbackExtraArgs extra arguments that will be passed to the callback methods; can be used to identify from which request the response arrived when using the same callback method for multiple requests. Please use only simple JSON arguments (primitive types or array/objects of primitive types)
Returns: void
Sample
executeAsyncRequest(username, password, successCallbackMethod, errorCallbackMethod)
Execute the request method asynchronous. Success callback method will be called when response is received. Response is sent as parameter in callback. This Response can be a response with a different status code then just 200, it could also be 500, which is still a valid response from the server, this won't go into the error callback. So you need to test the Reponse.getStatusCode() for that to know if everything did go OK. If no response is received (request errors out), the errorCallbackMethod is called with exception message as parameter.
Parameters
String username the user name
String password the password
Function successCallbackMethod callbackMethod to be called after response is received
Function errorCallbackMethod callbackMethod to be called if request errors out
Returns: void
Sample
executeAsyncRequest(username, password, successCallbackMethod, errorCallbackMethod, callbackExtraArgs)
Execute the request method asynchronous using windows authentication. Success callback method will be called when response is received. Response is sent as parameter in callback followed by any 'callbackExtraArgs' that were given. This Response can be a response with a different status code then just 200, it could also be 500, which is still a valid response from the server, this won't go into the error callback. So you need to test the Reponse.getStatusCode() for that to know if everything did go OK. If no response is received (request errors out, network errors), the errorCallbackMethod is called with exception message as parameter followed by any 'callbackExtraArgs' that were given.
Parameters
String username the user name
String password the password
Function successCallbackMethod callbackMethod to be called after response is received
Function errorCallbackMethod callbackMethod to be called if request errors out
Array callbackExtraArgs extra arguments that will be passed to the callback methods; can be used to identify from which request the response arrived when using the same callback method for multiple requests. Please use only simple JSON arguments (primitive types or array/objects of primitive types)
Returns: void
Sample
executeAsyncRequest(successCallbackMethod, errorCallbackMethod)
Execute the request method asynchronous. Success callback method will be called when response is received. Response is sent as parameter in callback. This Response can be a response with a different status code then just 200, it could also be 500, which is still a valid response from the server, this won't go into the error callback. So you need to test the Reponse.getStatusCode() for that to know if everything did go OK. If no response is received (request errors out), the errorCallbackMethod is called with exception message as parameter.
Parameters
Function successCallbackMethod callbackMethod to be called after response is received
Function errorCallbackMethod callbackMethod to be called if request errors out
Returns: void
Sample
executeAsyncRequest(successCallbackMethod, errorCallbackMethod, callbackExtraArgs)
Execute the request method asynchronous using windows authentication. Success callback method will be called when response is received. Response is sent as parameter in callback followed by any 'callbackExtraArgs' that were given. This Response can be a response with a different status code then just 200, it could also be 500, which is still a valid response from the server, this won't go into the error callback. So you need to test the Reponse.getStatusCode() for that to know if everything did go OK. If no response is received (request errors out, network errors), the errorCallbackMethod is called with exception message as parameter followed by any 'callbackExtraArgs' that were given.
Parameters
Function successCallbackMethod callbackMethod to be called after response is received
Function errorCallbackMethod callbackMethod to be called if request errors out
Array callbackExtraArgs extra arguments that will be passed to the callback methods; can be used to identify from which request the response arrived when using the same callback method for multiple requests. Please use only simple JSON arguments (primitive types or array/objects of primitive types)
Returns: void
Sample
executeRequest()
Execute the request method.
Returns: Response
Sample
executeRequest(userName, password)
Execute the request method.
Parameters
Returns: Response
Sample
executeRequest(userName, password, workstation, domain)
Execute a request method using windows authentication.
Parameters
String userName the user name
String password the password
String workstation The workstation the authentication request is originating from.
String domain The domain to authenticate within.
Returns: Response
Sample
getAllowedMethods(res)
Returns the supported HTTP Request operations as a String Array
Parameters
Response res The response request to get the allowed methods from.
Returns: Array
Sample
usePreemptiveAuthentication(b)
Whatever to use preemptive authentication (sending the credentials in the header, avoiding the server request to the client - useful when uploading files, as some http servers would cancel the first request from the client, if too big, as the authentication request to the client was not yet sent)
Parameters
Boolean b ;
Returns: void
Last updated