Qore jni Module  1.2.0
org.qore.lang.restclient.RestClient Class Reference

Java wrapper for the Qore::RestClient class in Qore. More...

Inheritance diagram for org.qore.lang.restclient.RestClient:
org.qore.lang.HTTPClient org.qore.jni.QoreObjectWrapper

Public Member Methods

 RestClient (QoreObject ds)
 creates the object
 
 RestClient (Map< String, Object > opts, boolean do_not_connect) throws Throwable
 calls the base class HTTPClient constructor and optionally connects to the REST server More...
 
 RestClient (Map< String, Object > opts) throws Throwable
 calls the base class HTTPClient constructor and optionally connects to the REST server More...
 
 RestClient () throws Throwable
 calls the base class HTTPClient constructor and optionally connects to the REST server More...
 
void setSerialization (String data) throws Throwable
 change the serialization option for the object; see DataSerializationOptions for valid options More...
 
void setSendEncoding (String enc) throws Throwable
 change the data content encoding (compression) option for the object; see EncodingSupport for valid options More...
 
void setContentEncoding (String enc) throws Throwable
 sets the request and desired response encoding for the object; see EncodingSupport for valid options More...
 
void addDefaultHeaders (Map< String, Object > h) throws Throwable
 adds default headers to each request; these headers will be sent in all requests but can be overridden in requests as well More...
 
HashMap< String, Object > getDefaultHeaders () throws Throwable
 returns the hash of default headers to sent in all requests More...
 
String getSendEncoding () throws Throwable
 returns the current data content encoding (compression) object or null if no encoding option is set; see EncodingSupport for valid options More...
 
String getSerialization () throws Throwable
 returns the current data serialization format currently in effect for the object (see DataSerializationOptions for possible values) More...
 
HashMap< String, Object > restGet (String path, Map< String, Object > hdr) throws Throwable
 sends an HTTP GET request to the REST server and returns the response More...
 
HashMap< String, Object > restGet (String path, Object body, Map< String, Object > hdr) throws Throwable
 sends an HTTP GET request to the REST server and returns the response More...
 
HashMap< String, Object > restGet (String path) throws Throwable
 sends an HTTP GET request to the REST server and returns the response More...
 
HashMap< String, Object > restPut (String path, Object body, Map< String, Object > hdr) throws Throwable
 sends an HTTP PUT request to the REST server and returns the response More...
 
HashMap< String, Object > restPut (String path, Object body) throws Throwable
 sends an HTTP PUT request to the REST server and returns the response More...
 
HashMap< String, Object > restPatch (String path, Object body, Map< String, Object > hdr) throws Throwable
 sends an HTTP PATCH request to the REST server and returns the response More...
 
HashMap< String, Object > restPatch (String path, Object body) throws Throwable
 sends an HTTP PATCH request to the REST server and returns the response More...
 
HashMap< String, Object > restPost (String path, Object body, Map< String, Object > hdr) throws Throwable
 sends an HTTP POST request to the REST server and returns the response More...
 
HashMap< String, Object > restPost (String path, Object body) throws Throwable
 sends an HTTP POST request to the REST server and returns the response More...
 
HashMap< String, Object > restDel (String path, Object body, Map< String, Object > hdr) throws Throwable
 sends an HTTP DELETE request to the REST server and returns the response More...
 
HashMap< String, Object > restDel (String path, Object body) throws Throwable
 sends an HTTP DELETE request to the REST server and returns the response More...
 
HashMap< String, Object > doRequest (String m, String path, Object body, boolean decode_errors, Map< String, Object > hdr) throws Throwable
 sends an HTTP request to the REST server and returns the response More...
 
HashMap< String, Object > doRequest (String m, String path, Object body, boolean decode_errors) throws Throwable
 sends an HTTP request to the REST server and returns the response More...
 
HashMap< String, Object > doRequest (String m, String path, Object body) throws Throwable
 sends an HTTP request to the REST server and returns the response More...
 
- Public Member Methods inherited from org.qore.lang.HTTPClient
 HTTPClient (QoreObject ds)
 creates the object
 
 HTTPClient (Map< String, Object > opts) throws Throwable
 Creates the HTTPClient object based on the option parameter passed. More...
 
void setHTTPVersion (String ver) throws Throwable
 Sets the HTTP protocol version string for headers in outgoing messages, allowed values are "1.0" and "1.1". More...
 
String getHTTPVersion () throws Throwable
 Returns the HTTP protocol version string used in outgoing messages. More...
 
void setSecure (boolean secure) throws Throwable
 Sets the object to make a secure SSL/TLS connection on the next connect if the passed argument is true, or an unencrypted cleartext connection if it is false. More...
 
boolean isSecure () throws Throwable
 Returns true if the current connection is encrypted, false if not. More...
 
void connect () throws Throwable
 Connects to the remote socket; SSL/TLS negotiation is performed if required. More...
 
void disconnect () throws Throwable
 Disconnects from the remote socket if a connection is established (otherwise does nothing) More...
 
HashMap< String, Object > send (String body, String method, String path, Map< String, Object > headers, boolean getbody) throws Throwable
 Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. More...
 
HashMap< String, Object > send (String body, String method, String path, Map< String, Object > headers) throws Throwable
 Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. More...
 
HashMap< String, Object > send (String body, String method, String path) throws Throwable
 Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. More...
 
HashMap< String, Object > send (String body, String method) throws Throwable
 Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. More...
 
HashMap< String, Object > send (byte[] body, String method, String path, Map< String, Object > headers, boolean getbody) throws Throwable
 Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. More...
 
HashMap< String, Object > send (byte[] body, String method, String path, Map< String, Object > headers) throws Throwable
 Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. More...
 
HashMap< String, Object > send (byte[] body, String method, String path) throws Throwable
 Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. More...
 
HashMap< String, Object > send (byte[] body, String method) throws Throwable
 Sends an HTTP request with the specified method and optional message body and returns headers and any body received as a response in a hash format. More...
 
String get (String path, Map< String, Object > headers) throws Throwable
 Sends an HTTP GET request and returns the message body received as a string or null if no message body is received. More...
 
String get (String path) throws Throwable
 Sends an HTTP GET request and returns the message body received as a string or null if no message body is received. More...
 
String head (String path, Map< String, Object > headers) throws Throwable
 Sends an HTTP HEAD request and returns as hash of the headers received. More...
 
String head (String path) throws Throwable
 Sends an HTTP HEAD request and returns as hash of the headers received. More...
 
String post (String path, String body, Map< String, Object > headers) throws Throwable
 Sends an HTTP POST request with a message body and returns the message body received as a string or null if no message body is received. More...
 
String post (String path, String body) throws Throwable
 Sends an HTTP POST request with a message body and returns the message body received as a string or null if no message body is received. More...
 
String post (String path) throws Throwable
 Sends an HTTP POST request without a message body and returns the response message body received as a string or null if no message body is received. More...
 
String post (String path, byte[] body, Map< String, Object > headers) throws Throwable
 Sends an HTTP POST request with a message body and returns the message body received as a string or null if no message body is received. More...
 
String post (String path, byte[] body) throws Throwable
 Sends an HTTP POST request with a message body and returns the message body received as a string or null if no message body is received. More...
 
void setTimeout (int timeout_ms) throws Throwable
 Sets the default I/O timeout value in milliseconds. More...
 
int getTimeout () throws Throwable
 Returns the default I/O timeout as an integer in milliseconds. More...
 
void setEncoding (String encoding) throws Throwable
 Sets the string encoding for the object; any strings deserialized with this object will be tagged with this character encoding. More...
 
String getEncoding () throws Throwable
 Returns the character encoding used for the object. More...
 
void setURL (String url) throws Throwable
 Sets a new URL value for the next connection. More...
 
String getURL () throws Throwable
 Returns the current URL. More...
 
void setProxyURL () throws Throwable
 Clears the new proxy URL value for the next connection. More...
 
void setProxyURL (String url) throws Throwable
 Sets a new proxy URL value for the next connection. More...
 
String getProxyURL () throws Throwable
 Returns the current proxy URL as a string or null if no proxy URL is set. More...
 
void clearProxyURL () throws Throwable
 Clears the new proxy URL value for the next connection. More...
 
void setProxySecure (boolean b) throws Throwable
 Sets the SSL/TLS flag for the next connection to the proxy. More...
 
boolean isProxySecure () throws Throwable
 Returns the SSL/TLS flag for the next proxy connection. More...
 
void setMaxRedirects (int mr) throws Throwable
 Updates the setting for the max_redirects value for the object (maximum number of HTTP redirects that will be processed before an exception is raised) More...
 
int getMaxRedirects () throws Throwable
 Returns the current max_redirects value for the object (the maximum number of HTTP redirects that will be processed before an exception is raised) More...
 
void setConnectTimeout (int timeout_ms) throws Throwable
 Sets the connect timeout in milliseconds. More...
 
int getConnectTimeout () throws Throwable
 Returns the connect timeout as an integer in milliseconds. More...
 
int setNoDelay (boolean b) throws Throwable
 Sets the TCP_NODELAY setting for the object. More...
 
boolean getNoDelay () throws Throwable
 Returns the TCP_NODELAY setting for the HTTPClient object. More...
 
boolean isConnected () throws Throwable
 Returns true or false giving the current connection state. More...
 
void setUserPassword (String user, String pass) throws Throwable
 Sets the username and password for the connection; call after HTTPClient::setURL() More...
 
void setUserPassword () throws Throwable
 Clears the username and password for the connection. More...
 
void clearUserPassword () throws Throwable
 Clears the username and password for the connection. More...
 
void setProxyUserPassword (String user, String pass) throws Throwable
 Sets the username and password for the connection to the proxy; call after HTTPClient::setProxyURL() More...
 
void setProxyUserPassword () throws Throwable
 Clears the username and password for the next proxy connection. More...
 
void clearProxyUserPassword () throws Throwable
 Clears the username and password for the next proxy connection. More...
 
void setDefaultPath (String path) throws Throwable
 Sets the default path used by the object if no path is set in the URL. More...
 
String getDefaultPath () throws Throwable
 Returns the default path used by the object if no path is set in the URL. More...
 
String getConnectionPath () throws Throwable
 Returns the current connection path set in the URL. More...
 
void setConnectionPath (String uri_path) throws Throwable
 Overrides any connection path set in the URL. More...
 
void setConnectionPath () throws Throwable
 Overrides any connection path set in the URL. More...
 
HashMap< String, Object > getUsageInfo () throws Throwable
 Returns performance statistics for the socket. More...
 
void clearStats () throws Throwable
 Clears performance statistics. More...
 
void setPersistent () throws Throwable
 temporarily disables implicit reconnections; must be called when the server is already connected More...
 
boolean setErrorPassthru (boolean set) throws Throwable
 set the error passthru status More...
 
boolean setErrorPassthru () throws Throwable
 set the error passthru status More...
 
boolean getErrorPassthru () throws Throwable
 get the error passthru status More...
 
boolean setRedirectPassthru (boolean set) throws Throwable
 set the redirect passthru status More...
 
boolean setRedirectPassthru () throws Throwable
 set the redirect passthru status More...
 
boolean getRedirectPassthru () throws Throwable
 get the redirect passthru status More...
 
boolean setEncodingPassthru (boolean set) throws Throwable
 set the encoding passthru status More...
 
boolean setEncodingPassthru () throws Throwable
 set the encoding passthru status More...
 
boolean getEncodingPassthru () throws Throwable
 get the encoding passthru status More...
 
String getHostHeaderValue () throws Throwable
 returns the Host header value for this object More...
 
- Public Member Methods inherited from org.qore.jni.QoreObjectWrapper
 QoreObjectWrapper (QoreObject obj)
 creates the wrapper object with the Qore object
 
void release ()
 releases the Qore object; do not call any further methods on the object after this call
 
QoreObject getQoreObject ()
 returns the Qore object
 
String className ()
 returns the class name for the Qore object
 
boolean instanceOf (String class_name)
 returns true if the object is an instance of the given class
 

Additional Inherited Members

- Private Attributes inherited from org.qore.jni.QoreObjectWrapper
QoreObject obj
 the wrapper Qore object
 

Detailed Description

Java wrapper for the Qore::RestClient class in Qore.

Note
Loads and initializes the Qore library and the jni module in static initialization if necessary

Constructor & Destructor Documentation

◆ RestClient() [1/3]

org.qore.lang.restclient.RestClient.RestClient ( Map< String, Object >  opts,
boolean  do_not_connect 
) throws Throwable
inline

calls the base class HTTPClient constructor and optionally connects to the REST server

Example:
HashMap<String, Object> opts = new HashMap<String, Object>() {
{
put("url", "http://localhost:8001/rest");
}
};
RestClient rest = new RestClient(opts);
Parameters
optsvalid options are:
  • additional_methods: Optional hash with more but not-HTTP-standardized methods to handle. It allows to create various HTTP extensions like e.g. WebDAV. The hash takes the method name as a key, and the value is a boolean true or false: indicating if the method can accept a message body as well. Example:
    // add new HTTP methods for WebDAV. Both of them require body posting to the server
    {"additional_methods": {"PROPFIND": true, "MKCOL": true}};
  • connect_timeout: The timeout value in milliseconds for establishing a new socket connection (also can be a relative date-time value for clarity, ex: 20s)
  • content_encoding: for possible values, see EncodingSupport; this sets the send encoding (if the "send_encoding" option is not set) and the requested response encoding (note that the RestClient class will only compress outgoing message bodies over CompressionThreshold bytes in size)
  • data: a data serialization option; if not present defaults to "auto"
  • default_path: The default path to use for new connections if a path is not otherwise specified in the connection URL
  • default_port: The default port number to connect to if none is given in the URL
  • error_passthru: if true then HTTP status codes indicating errors will not cause a REST-RESPONSE-ERROR exception to be raised, rather such responses will be passed through to the caller like any other response
  • headers: an optional hash of headers to send with every request, these can also be overridden in request method calls
  • http_version: Either '1.0' or '1.1' for the claimed HTTP protocol version compliancy in outgoing message headers
  • max_redirects: The maximum number of redirects before throwing an exception (the default is 5)
  • proxy: The proxy URL for connecting through a proxy
  • redirect_passthru: if true then redirect responses will be passed to the caller instead of processed
  • send_encoding: a send data encoding option or the value "auto" which means to use automatic encoding; if not present defaults to no content-encoding on sent message bodies (note that the RestClient class will only compress outgoing message bodies over CompressionThreshold bytes in size)
  • swagger: the path to a Swagger 2.0 REST schema file for API validation; only used if validator not provided (see the Swagger module)
  • timeout: The timeout value in milliseconds (also can be a relative date-time value for clarity, ex: 30s)
  • url: A string giving the URL to connect to; if not given then the target URL will be taken from any validator option, if given by calling AbstractRestSchemaValidator::getTargetUrl()
  • validator: an AbstractRestSchemaValidator object to validate request and response messages; overrides swagger
  • no_charset: if true no charset will be added to the Content-Type header
do_not_connectif False (the default), then a connection will be immediately established to the remote server
Exceptions
RESTCLIENT-ERRORinvalid option passed to constructor, unsupported data serialization, etc

◆ RestClient() [2/3]

org.qore.lang.restclient.RestClient.RestClient ( Map< String, Object >  opts) throws Throwable
inline

calls the base class HTTPClient constructor and optionally connects to the REST server

Example:
HashMap<String, Object> opts = new HashMap<String, Object>() {
{
put("url", "http://localhost:8001/rest");
}
};
RestClient rest = new RestClient(opts);
Parameters
optsvalid options are:
  • additional_methods: Optional hash with more but not-HTTP-standardized methods to handle. It allows to create various HTTP extensions like e.g. WebDAV. The hash takes the method name as a key, and the value is a boolean true or false: indicating if the method can accept a message body as well. Example:
    // add new HTTP methods for WebDAV. Both of them require body posting to the server
    {"additional_methods": {"PROPFIND": true, "MKCOL": true}};
  • connect_timeout: The timeout value in milliseconds for establishing a new socket connection (also can be a relative date-time value for clarity, ex: 20s)
  • content_encoding: for possible values, see EncodingSupport; this sets the send encoding (if the "send_encoding" option is not set) and the requested response encoding (note that the RestClient class will only compress outgoing message bodies over CompressionThreshold bytes in size)
  • data: a data serialization option; if not present defaults to "auto"
  • default_path: The default path to use for new connections if a path is not otherwise specified in the connection URL
  • default_port: The default port number to connect to if none is given in the URL
  • error_passthru: if true then HTTP status codes indicating errors will not cause a REST-RESPONSE-ERROR exception to be raised, rather such responses will be passed through to the caller like any other response
  • headers: an optional hash of headers to send with every request, these can also be overridden in request method calls
  • http_version: Either '1.0' or '1.1' for the claimed HTTP protocol version compliancy in outgoing message headers
  • max_redirects: The maximum number of redirects before throwing an exception (the default is 5)
  • proxy: The proxy URL for connecting through a proxy
  • redirect_passthru: if true then redirect responses will be passed to the caller instead of processed
  • send_encoding: a send data encoding option or the value "auto" which means to use automatic encoding; if not present defaults to no content-encoding on sent message bodies (note that the RestClient class will only compress outgoing message bodies over CompressionThreshold bytes in size)
  • swagger: the path to a Swagger 2.0 REST schema file for API validation; only used if validator not provided (see the Swagger module)
  • timeout: The timeout value in milliseconds (also can be a relative date-time value for clarity, ex: 30s)
  • url: A string giving the URL to connect to; if not given then the target URL will be taken from any validator option, if given by calling AbstractRestSchemaValidator::getTargetUrl()
  • validator: an AbstractRestSchemaValidator object to validate request and response messages; overrides swagger
  • no_charset: if true no charset will be added to the Content-Type header
Exceptions
RESTCLIENT-ERRORinvalid option passed to constructor, unsupported data serialization, etc

◆ RestClient() [3/3]

org.qore.lang.restclient.RestClient.RestClient ( ) throws Throwable
inline

calls the base class HTTPClient constructor and optionally connects to the REST server

Example:
RestClient rest = new RestClient();

Member Function Documentation

◆ addDefaultHeaders()

void org.qore.lang.restclient.RestClient.addDefaultHeaders ( Map< String, Object >  h) throws Throwable
inline

adds default headers to each request; these headers will be sent in all requests but can be overridden in requests as well

Example:
// disable gzip and bzip encoding in responses
rest.addDefaultHeaders(("Accept-Encoding": "compress"));
Parameters
ha hash of headers to add to the default headers to send on each request
Note
default headers can also be set in the constructor
See also
getDefaultHeaders()
Since
RestClient 1.3

◆ doRequest() [1/3]

HashMap<String, Object> org.qore.lang.restclient.RestClient.doRequest ( String  m,
String  path,
Object  body 
) throws Throwable
inline

sends an HTTP request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.doRequest("DELETE", "/orders/1");
Parameters
mthe HTTP method to be used; case is ignored (if not a valid method an HTTP-CLIENT-METHOD-ERROR exception is raised)
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
HTTP-CLIENT-METHOD-ERRORinvalid HTTP method argument passed
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true
REST-ACCEPT-ERRORif the message has a validator that indicates that the response message only supports types not supported by the current options or environment

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ doRequest() [2/3]

HashMap<String, Object> org.qore.lang.restclient.RestClient.doRequest ( String  m,
String  path,
Object  body,
boolean  decode_errors 
) throws Throwable
inline

sends an HTTP request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.doRequest("DELETE", "/orders/1");
Parameters
mthe HTTP method to be used; case is ignored (if not a valid method an HTTP-CLIENT-METHOD-ERROR exception is raised)
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
decode_errorsdecode the message body with HTTP error responses and throw an exception based on the message body
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
HTTP-CLIENT-METHOD-ERRORinvalid HTTP method argument passed
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true
REST-ACCEPT-ERRORif the message has a validator that indicates that the response message only supports types not supported by the current options or environment

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ doRequest() [3/3]

HashMap<String, Object> org.qore.lang.restclient.RestClient.doRequest ( String  m,
String  path,
Object  body,
boolean  decode_errors,
Map< String, Object >  hdr 
) throws Throwable
inline

sends an HTTP request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.doRequest("DELETE", "/orders/1");
Parameters
mthe HTTP method to be used; case is ignored (if not a valid method an HTTP-CLIENT-METHOD-ERROR exception is raised)
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
decode_errorsdecode the message body with HTTP error responses and throw an exception based on the message body
hdrany headers to be sent with the request; headers here will override default headers for the object as well
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
HTTP-CLIENT-METHOD-ERRORinvalid HTTP method argument passed
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true
REST-ACCEPT-ERRORif the message has a validator that indicates that the response message only supports types not supported by the current options or environment

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ getDefaultHeaders()

HashMap<String, Object> org.qore.lang.restclient.RestClient.getDefaultHeaders ( ) throws Throwable
inline

returns the hash of default headers to sent in all requests

Example:
HashMap<String, Object> h = rest.getDefaultHeaders();
Returns
the hash of default headers to sent in all requests
Note
default headers can be set in the constructor and in addDefaultHeaders()
See also
addDefaultHeaders()
Since
RestClient 1.3

◆ getSendEncoding()

String org.qore.lang.restclient.RestClient.getSendEncoding ( ) throws Throwable
inline

returns the current data content encoding (compression) object or null if no encoding option is set; see EncodingSupport for valid options

Example:
String ce = rest.getSendEncoding();
Returns
the current data content encoding (compression) object or null if no encoding option is set; see EncodingSupport for valid options
See also
Since
RestClient 1.3

◆ getSerialization()

String org.qore.lang.restclient.RestClient.getSerialization ( ) throws Throwable
inline

returns the current data serialization format currently in effect for the object (see DataSerializationOptions for possible values)

Example:
String ser = rest.getSerialization();
Returns
the current data serialization format currently in effect for the object (see DataSerializationOptions for possible values)
See also
setSerialization()

◆ restDel() [1/2]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restDel ( String  path,
Object  body 
) throws Throwable
inline

sends an HTTP DELETE request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.del("/orders/1");
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restDel() [2/2]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restDel ( String  path,
Object  body,
Map< String, Object >  hdr 
) throws Throwable
inline

sends an HTTP DELETE request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.del("/orders/1");
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
hdrany headers to be sent with the request; headers here will override default headers for the object as well
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restGet() [1/3]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restGet ( String  path) throws Throwable
inline

sends an HTTP GET request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.get("/orders/1?info=verbose");
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restGet() [2/3]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restGet ( String  path,
Map< String, Object >  hdr 
) throws Throwable
inline

sends an HTTP GET request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.get("/orders/1?info=verbose");
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
hdrany headers to be sent with the request; headers here will override default headers for the object as well
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restGet() [3/3]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restGet ( String  path,
Object  body,
Map< String, Object >  hdr 
) throws Throwable
inline

sends an HTTP GET request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.get("/orders/1?info=verbose");
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor(); note that sending a message body with an HTTP GET request is not standards compliant; see httpclient_get_with_body for more information; for maximum compatibility, use null for this argument when calling this method
hdrany headers to be sent with the request; headers here will override default headers for the object as well
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restPatch() [1/2]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restPatch ( String  path,
Object  body 
) throws Throwable
inline

sends an HTTP PATCH request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.patch("/orders/1", ("action": "cancel"));
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restPatch() [2/2]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restPatch ( String  path,
Object  body,
Map< String, Object >  hdr 
) throws Throwable
inline

sends an HTTP PATCH request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.patch("/orders/1", ("action": "cancel"));
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
hdrany headers to be sent with the request; headers here will override default headers for the object as well
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restPost() [1/2]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restPost ( String  path,
Object  body 
) throws Throwable
inline

sends an HTTP POST request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.post("/orders", ("product": "xyz123", "options": 500));
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restPost() [2/2]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restPost ( String  path,
Object  body,
Map< String, Object >  hdr 
) throws Throwable
inline

sends an HTTP POST request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.post("/orders", ("product": "xyz123", "options": 500));
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
hdrany headers to be sent with the request; headers here will override default headers for the object as well
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restPut() [1/2]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restPut ( String  path,
Object  body 
) throws Throwable
inline

sends an HTTP PUT request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.put("/orders/1", ("action": "cancel"));
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ restPut() [2/2]

HashMap<String, Object> org.qore.lang.restclient.RestClient.restPut ( String  path,
Object  body,
Map< String, Object >  hdr 
) throws Throwable
inline

sends an HTTP PUT request to the REST server and returns the response

Example:
HashMap<String, Object> ans = rest.put("/orders/1", ("action": "cancel"));
Parameters
paththe URI path to add (will be appended to any root path given in the constructor)
bodyan optional message body to be included in the request; if a value for this parameter is passed to the method, then the body will be serialized according to the serialization rules set in RestClient::constructor()
hdrany headers to be sent with the request; headers here will override default headers for the object as well
Returns
A hash of headers received from the HTTP server with all key names converted to lower-case; if any message body is included in the response, it will be deserialized to Qore data and assigned to the value of the "body" key
Exceptions
DESERIALIZATION-ERRORthe response body could not be deserialized (unknown Content-Type or invalid serialization)
REST-RESPONSE-ERRORif this exception is thrown by the Qore::HTTPClient::send() call in case of an HTTP response code < 100 or >= 300, the message body is still deserialized if possible and the response information can be retrieved in the info hash output keys as follows:
  • "response-code": the HTTP response code given
  • "response-headers": a hash of processed response headers
  • "response-headers-raw": a hash of raw unprocessed response headers
  • "response-body": the decoded response body
Note that this exception is not raised for HTTP status codes indicating an error if the error_passthru option is set to true

Other exceptions can be thrown by the Qore::HTTPClient::send() call used to make the HTTP request.

See also

◆ setContentEncoding()

void org.qore.lang.restclient.RestClient.setContentEncoding ( String  enc) throws Throwable
inline

sets the request and desired response encoding for the object; see EncodingSupport for valid options

Example:
rest.setContentEncoding("gzip");
Parameters
encthe data content encoding (compression) option for requests and the desired response content encoding for the object; see EncodingSupport for valid options; if the value "auto" is passed then "gzip" encoding is used for outgoing requests and requested for responses
Exceptions
RESTCLIENT-ERRORinvalid or unsupported data content encoding / compression option
See also
Since
RestClient 1.3

◆ setSendEncoding()

void org.qore.lang.restclient.RestClient.setSendEncoding ( String  enc) throws Throwable
inline

change the data content encoding (compression) option for the object; see EncodingSupport for valid options

Example:
rest.setSendEncoding("gzip");

The default is to send requests unencoded/uncompressed.

Parameters
encthe data content encoding (compression) option for the object; see EncodingSupport for valid options; if the value "auto" is passed then "gzip" encoding is used
Exceptions
RESTCLIENT-ERRORinvalid or unsupported data content encoding / compression option
See also

◆ setSerialization()

void org.qore.lang.restclient.RestClient.setSerialization ( String  data) throws Throwable
inline

change the serialization option for the object; see DataSerializationOptions for valid options

Example:
rest.setSerialization("yaml");
Parameters
datathe serialization option for the object; see DataSerializationOptions for valid options
Exceptions
RESTCLIENT-ERRORinvalid or unsupported serialization option
See also
getSerialization()

The documentation for this class was generated from the following file:
org.qore.lang.restclient.RestClient.RestClient
RestClient()
calls the base class HTTPClient constructor and optionally connects to the REST server
Definition: RestClient.java:135