![]() |
Qore RestClient Module Reference 2.3.3
|
The RestClient module provides an API for calling REST services.
To use this module, use "%requires RestClient" in your code.
All the public symbols in the module are defined in the RestClient namespace.
The main classes are:
The RestClient class can support the following methods of data serialization:
"json": using the "json" module; messages bodies are encoded using JSON"rawxml": using the "xml" module; message bodies are encoded with XML without any data type encodings"url": message bodies are encoded in URL form encoded format (see RFC 2738 2.2)"xml": using the "xml" module; message bodies are encoded using XML-RPC value encoding"yaml": using the "yaml" module; message bodies are encoded using YAML"text": message bodies are not serialized, plain text value is used"bin": message bodies are not serialized, binary data is used insteadIf none of the above modules can be loaded by the RestClient module, then the RestClient module will fail to initialize.
Runtime REST API validation against a REST schema is supported; see the validator, openapi3, and swagger options in RestClient::RestClient::constructor() "RestClient::constructor()".
For maximum compatibility with other REST solutions, the "json" encoding method is the default when no other encoding method is chosen and the "json" module is available.
"rest" in the bin directory for a user-friendly command-line interface to REST functionality and a more detailed example of code using this module.GET requests to be made with a message body, but this is bad practice and not compliant with HTTP 1.1 RFCs and therefore could lead to compatibility problems; see HTTP GET Requests With a Message Body for more informationThe info output hash to REST methods has the following format:
headers: a hash of outgoing HTTP request headersrequest-uri: the request URI string sent (ex: "GET /services/async/38.0/job HTTP/1.1")body-content-type: the outgoing message body Mime Content-Type valueresponse-headers: a hash of processed incoming HTTP headers in the response with keys converted to lower case and additional information addedresponse-headers-raw: a hash of raw unprocessed incoming HTTP headerschunked: set to True if the response was received with chunked transfer encodingresponse-body: the message body in the response (after any content decoding and deserialization)response-body-raw: the raw message body in the response (after any content decoding)response-code: the HTTP response coderesponse-serialization: the type of message serialization in the response; see DataSerializationOptions for possible values when used with the null REST schema validatorrequest-body: the raw message body in the request (before any content encoding)request-serialization: the type of message serialization in the request; see DataSerializationOptions for possible values when used with the null REST schema validatoroauth2_token_use_basic_auth option is set (issue 4991)client_credentials grant (issue 4990)allow_any_response option to allow undeserializable responses to be returned as-isswagger_lax_parsing option to try to parse invalid Swagger schemas (issue 4741)swagger_base_path argument to all REST validators (issue 4663)Content-Type headers in responses (issue 4019)no_charset option to options (issue 3328)"response-code" key of the info output hash could be missing in some clases (issue 3237)RestClient::RestConnection::getConstructorInfo() "RestConnection::getConstructorInfo()" method to allow connections to be created dynamically, potentially in another process from a network call (issue 2628)"bin" serialization method (issue 2816)text/plain Content-Type"PATCH" method"url" encoding for URL form encoded message bodies (issue 1436)"rawxml" data type; when parsing XML responses, if the XML cannot be parsed as XML-RPC data, then it's attempted to be parsed as untyped XML data (issue 1437)"content_encoding" option for the RestClient constructor"gzip" the default content encoding"/" chars were sometimes present in the request URI path"Content-Type" header in requests"Accept" header in requests