PatchRequest
Last updated
Was this helpful?
Last updated
Was this helpful?
The PatchRequest
class facilitates handling HTTP PATCH requests for updating resources on a server. It supports adding files, parameters, and headers to requests while providing methods to configure the request body and authentication options.
Developers can include files in the request with addFile()
methods, which support specifying file details and MIME types. Parameters can be added using addParameter()
, with support for custom MIME types when required. For configuring request bodies directly, the setBodyContent()
method is available with optional MIME type specifications.
Requests can be executed synchronously using executeRequest()
or asynchronously with executeAsyncRequest()
, offering support for callbacks to handle responses or errors. Authentication options include preemptive authentication, Windows authentication, and user credentials, ensuring compatibility with various server requirements. The forceMultipart()
method allows requests to be formatted as multipart/form-data
when needed, even for single-file uploads.
A sample creating a PatchRequest
can be found here: .
Add a file to the post; it will try to get the correct mime type from the file name or the first bytes.
Add a file to the post with a given mime type; could also be used to force the default 'application/octet-stream' on it, because this plugin will try to guess the correct mime type for the given file otherwise (based on the name or the bytes).
Add a file to the post; it will try to get the correct mime type from the file name or the first bytes.
Add a file to the post with a given mime type; could also be used to force the default 'application/octet-stream' on it, because this plugin will try to guess the correct mime type for the given file otherwise (based on the name or the bytes).
Add a file to the post; it will try to get the correct mime type from the file name or the first bytes.
Add a file to the post with a given mime type; could also be used to force the default 'application/octet-stream' on it, because this plugin will try to guess the correct mime type for the given file otherwise (based on the name or the bytes).
Add a header to the request.
Add a parameter to the post.
Add a parameter to the post.
Execute the request method asynchronous a Promise is returned which will be resolved or rejected when the request is completed or failed.
Execute the request method asynchronous a Promise is returned which will be resolved or rejected when the request is completed or failed.
Execute the request method asynchronous a Promise is returned which will be resolved or rejected when the request is completed or failed.
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.
void
Force this request to prepare a "Content-Type: multipart/form-data" formatted message even if only one file or only a number of parameter were added to it.
void
Set the body of the request.
void
Set the body of the request and content mime type.
void
Set the charset used when posting.
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)
Add a file to the post; it will try to get the correct mime type from the file name or the first bytes.
If you add a single file then this will be a single file (so not a multi-part) post. If you want/need multi-part then you have to either add multiple files or both a file and one or more parameters using addParameter(...).
Parameters
Sample
Add a file to the post with a given mime type; could also be used to force the default 'application/octet-stream' on it, because this plugin will try to guess the correct mime type for the given file otherwise (based on the name or the bytes).
If you add a single file then this will be a single file (so not a multi-part) post. If you want/need multi-part then you have to either add multiple files or both a file and one or more parameters using addParameter(...).
Parameters
Sample
Add a file to the post; it will try to get the correct mime type from the file name or the first bytes.
If you add a single file then this will be a single file (so not a multi-part) post. If you want/need multi-part then you have to either add multiple files or both a file and one or more parameters using addParameter(...).
Parameters
Sample
Add a file to the post with a given mime type; could also be used to force the default 'application/octet-stream' on it, because this plugin will try to guess the correct mime type for the given file otherwise (based on the name or the bytes).
If you add a single file then this will be a single file (so not a multi-part) post. If you want/need multi-part then you have to either add multiple files or both a file and one or more parameters using addParameter(...).
Parameters
Sample
Add a file to the post; it will try to get the correct mime type from the file name or the first bytes.
If you add a single file then this will be a single file (so not a multi-part) post. If you want/need multi-part then you have to either add multiple files or a file and at least a parameter via addParameter(...).
Parameters
Sample
Add a file to the post with a given mime type; could also be used to force the default 'application/octet-stream' on it, because this plugin will try to guess the correct mime type for the given file otherwise (based on the name or the bytes).
If you add a single file then this will be a single file (so not a multi-part) post. If you want/need multi-part then you have to either add multiple files or both a file and one or more parameters using addParameter(...).
Parameters
Sample
Add a header to the request.
Parameters
Sample
Add a parameter to the post.
If there is also at least one file added to this request using addFile(...) then a multi-part post will be generated.
Parameters
Sample
Add a parameter to the post.
If there is also at least one file added to this request using addFile(...) then a multi-part post will be generated. The multipart element will also contain content-type header, set from mimeType and charset. By default, this header is not present.
Parameters
Sample
Execute the request method asynchronous a Promise is returned which will be resolved or rejected when the request is completed or failed.
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. 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 Promise is rejected with exception message as the value.
You can use Promise.all([promise1, promise2, promise3]) to wait for multiple promises to complete. A shortcut for this would be to use httpClient.executeRequest(requestArray) that returns 1 promise that is called when all of them are done.
Sample
Execute the request method asynchronous a Promise is returned which will be resolved or rejected when the request is completed or failed.
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. 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 Promise is rejected with exception message as the value.
You can use Promise.all([promise1, promise2, promise3]) to wait for multiple promises to complete. A shortcut for this would be to use httpClient.executeRequest(requestArray) that returns 1 promise that is called when all of them are done.
Parameters
Sample
Execute the request method asynchronous a Promise is returned which will be resolved or rejected when the request is completed or failed.
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. 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 Promise is rejected with exception message as the value.
You can use Promise.all([promise1, promise2, promise3]) to wait for multiple promises to complete. A shortcut for this would be to use httpClient.executeRequest(requestArray) that returns 1 promise that is called when all of them are done.
Parameters
Sample
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
Returns: void
Sample
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
Returns: void
Sample
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
Returns: void
Sample
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
Returns: void
Sample
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
Returns: void
Sample
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
Returns: void
Sample
Execute the request method.
Sample
Execute the request method.
Parameters
Sample
Execute a request method using windows authentication.
Parameters
Sample
Force this request to prepare a "Content-Type: multipart/form-data" formatted message even if only one file or only a number of parameter were added to it.
It is useful because some servers require this (they only support multipart - even if you don't need to send multiple things). Before Servoy 2021.03 you could force it to send multipart by adding a dummy parameter together with a single file (or the other way around) - if the server didn't object to that dummy content...
Default value: false. (if you only add one file or only parameters it will not generate a multipart request)
Parameters
Returns: void
Set the body of the request.
Parameters
Returns: void
Sample
Set the body of the request and content mime type.
Parameters
Returns: void
Sample
Set the charset used when posting. If this is null or not called it will use the default charset (UTF-8).
Parameters
Returns: void
Sample
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
Returns: void
parameterName ;
jsFile ;
Returns: true if the JSFile was successfully added to the request, false otherwise.
parameterName ;
jsFile ;
mimeType The mime type that must be used could be the real default ('application/octet-stream') if the files one (by name or by its first bytes) is not good.
Returns: true if the JSFile with the specified mime type was successfully added, false otherwise.
parameterName ;
fileName ;
jsFile ;
Returns: true if the specified file was successfully added to the request, false otherwise.
parameterName ;
fileName ;
jsFile ;
mimeType The mime type that must be used could be the real default ('application/octet-stream') if the files one (by name or by its first bytes) is not good.
Returns: true if the file with the given parameters and mime type was successfully added, false otherwise.
parameterName ;
fileName ;
fileLocation ;
Returns: true if the file was successfully added to the request, false otherwise.
parameterName ;
fileName ;
fileLocation ;
mimeType The mime type that must be used could be the real default ('application/octet-stream') if the files one (by name or by its first bytes) is not good.
Returns: true if the file with the specified mime type was successfully added, false otherwise.
headerName ;
value ;
Returns: A boolean indicating whether the header was successfully added to the request.
name ;
value ;
Returns: true if the parameter was successfully added, false otherwise.
name ;
value ;
mimeType ;
Returns: true if the parameter with the specified mime type was successfully added, false otherwise.
Returns:
username the user name
password the password
Returns:
username the user name
password the password
workstation The workstation the authentication request is originating from.
domain The domain to authenticate within.
Returns:
username the user name
password the password
workstation The workstation the authentication request is originating from.
domain The domain to authenticate within.
successCallbackMethod callbackMethod to be called after response is received
errorCallbackMethod callbackMethod to be called if request errors out
username the user name
password the password
workstation The workstation the authentication request is originating from.
domain The domain to authenticate within.
successCallbackMethod callbackMethod to be called after response is received
errorCallbackMethod callbackMethod to be called if request errors out
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)
username the user name
password the password
successCallbackMethod callbackMethod to be called after response is received
errorCallbackMethod callbackMethod to be called if request errors out
username the user name
password the password
successCallbackMethod callbackMethod to be called after response is received
errorCallbackMethod callbackMethod to be called if request errors out
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)
successCallbackMethod callbackMethod to be called after response is received
errorCallbackMethod callbackMethod to be called if request errors out
successCallbackMethod callbackMethod to be called after response is received
errorCallbackMethod callbackMethod to be called if request errors out
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: A Response object containing the result of the executed HTTP request.
userName the user name
password the password
Returns: A Response object containing the result of the HTTP request, authenticated with the provided username and password.
userName the user name
password the password
workstation The workstation the authentication request is originating from.
domain The domain to authenticate within.
Returns: A Response object containing the result of the HTTP request, authenticated using Windows authentication with the provided credentials.
forceMultipart if true, this request will send a multipart/form-data message even if you only add one file or only parameters. If false (default) it will send multipart only in case of multiple files or one file plus at least one parameter.
content ;
content ;
mimeType ;
charset ;
b ;