All Classes Namespaces Functions Variables Groups Pages
RestClient Module

# RestClient Introduction

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:

- RestClient: this class provides the REST client API

The RestClient class can support three methods of data serialization:

- `"json"`: using the `"json"` module; messages bodies are encoded using JSON
- `"yaml"`: using the `"yaml"` module; message bodies are encoded using YAML
- `"xml"`: using the `"xml"` module; message bodies are encoded using XML-RPC value encoding

If none of the above modules can be loaded by the RestClient module, then the RestClient module will fail to initialize.

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.

Example:
  #!/usr/bin/env qore
  %requires RestClient
  RestClient rest(("url": "http://localhost:8001/rest"));
  hash ans = rest.get("orders/1?option=full");
  printf("%N\n", ans.body);

See example file `"rest"` in the examples directory for a more detailed example using this module

# Release Notes

## RestClient v1.3

- added:
  - RestClient::addDefaultHeaders()
  - RestClient::getDefaultHeaders()
  - RestClient::getSendEncoding()
  - RestClient::setContentEncoding()
- implemented the `"content_encoding"` option for the RestClient constructor
- made `"gzip"` the default content encoding
- added a compression threshold giving a minimum size for for applying content encoding on message bodies; small messages will be sent uncompressed
- when possible, REST bodies are decoded and stored in the info output argument when the HTTP server returns a status code < 100 or >= 300 to allow for error-handling in the client
- fixed issues where multiple leading `"/"` chars were sometimes present in the request URI path
- doc updates

## RestClient v1.2

- allow the Content-Type header to be overriden in REST requests
- added hdr args to REST methods
- fixed a bug using the module when the yaml module is not available
- ensure URI paths are absolute

## RestClient v1.1

- updated to use encode_url() before sending HTTP messages
- add charset=xxx to `"Content-Type"` header in requests
- fixed `"Accept"` header in requests

## RestClient v1.0

- the initial version of the RestClient module