[MXS-2260] Document examples on how to use REST API with popular REST clients Created: 2019-01-12  Updated: 2019-03-08  Resolved: 2019-03-08

Status: Closed
Project: MariaDB MaxScale
Component/s: Documentation, REST-API
Affects Version/s: 2.2.19, 2.3.2
Fix Version/s: 2.3.5

Type: Task Priority: Major
Reporter: Geoff Montee (Inactive) Assignee: markus makela
Resolution: Fixed Votes: 0
Labels: None

Sprint: MXS-SPRINT-75, MXS-SPRINT-76, MXS-SPRINT-77

 Description   

I think it would be helpful to document some examples on how to use the REST API with some popular REST clients, such as curl.

I did some testing myself.

First, I configured the following:

[maxscale]
...
admin_host=127.0.0.1
admin_port=8989
admin_auth=1
admin_enabled=1

And then I did some tests with the passive flag.

To read the value, I followed these directions:

https://mariadb.com/kb/en/mariadb-maxscale-23-maxscale-resource/#get-global-information

And did the following:

$ curl --include --basic --user "admin:mariadb" http://127.0.0.1:8989/v1/maxscale
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 1876
Last-Modified: Fri, 11 Jan 2019 23:50:34 GMT
ETag: "1"
Date: Fri, 11 Jan 19 23:52:01 GMT
Content-Type: application/json
 
{
    "links": {
        "self": "http://127.0.0.1:8989/v1/maxscale/"
    },
    "data": {
        "attributes": {
            "parameters": {
                "libdir": "/usr/lib64/maxscale",
                "datadir": "/var/lib/maxscale",
                "process_datadir": "/var/lib/maxscale/data2997",
                "cachedir": "/var/cache/maxscale",
                "configdir": "/etc",
                "config_persistdir": "/var/lib/maxscale/maxscale.cnf.d",
                "module_configdir": "/etc/maxscale.modules.d",
                "piddir": "/var/run/maxscale",
                "logdir": "/var/log/maxscale",
                "langdir": "/var/lib/maxscale",
                "execdir": "/usr/bin",
                "connector_plugindir": "/var/lib/plugin",
                "threads": 4,
                "thread_stack_size": 8388608,
                "writeq_high_water": 0,
                "writeq_low_water": 0,
                "auth_connect_timeout": 3,
                "auth_read_timeout": 1,
                "auth_write_timeout": 2,
                "skip_permission_checks": false,
                "admin_auth": true,
                "admin_enabled": true,
                "admin_log_auth_failures": true,
                "admin_host": "127.0.0.1",
                "admin_port": 8989,
                "admin_ssl_key": "",
                "admin_ssl_cert": "",
                "admin_ssl_ca_cert": "",
                "passive": true,
                "query_classifier": "",
                "query_classifier_cache_size": 415775129
            },
            "version": "2.3.2",
            "commit": "1126c687a4570f60ee26a163520198a3263ccbbd",
            "started_at": "Fri, 11 Jan 2019 23:21:26 GMT",
            "activated_at": "Fri, 11 Jan 2019 23:21:26 GMT",
            "uptime": 1835
        },
        "id": "maxscale",
        "type": "maxscale"
    }
}

And then to change the value, I followed these directions:

https://mariadb.com/kb/en/mariadb-maxscale-23-maxscale-resource/#update-maxscale-parameters

And did the following:

$ curl --include --request PATCH --basic --user "admin:mariadb" http://127.0.0.1:8989/v1/maxscale --data @- <<EOF
> {
>     "data": {
>         "attributes": {
>             "parameters": {
>                 "passive": false
>             }
>         }
>     }
> }
> EOF
HTTP/1.1 204 No Content
Connection: Keep-Alive
Date: Fri, 11 Jan 19 23:52:45 GMT

And then I confirmed that the value changed by reading it again:

$ curl --include --basic --user "admin:mariadb" http://127.0.0.1:8989/v1/maxscale
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 1877
Last-Modified: Fri, 11 Jan 2019 23:52:45 GMT
ETag: "2"
Date: Fri, 11 Jan 19 23:53:17 GMT
Content-Type: application/json
 
{
    "links": {
        "self": "http://127.0.0.1:8989/v1/maxscale/"
    },
    "data": {
        "attributes": {
            "parameters": {
                "libdir": "/usr/lib64/maxscale",
                "datadir": "/var/lib/maxscale",
                "process_datadir": "/var/lib/maxscale/data2997",
                "cachedir": "/var/cache/maxscale",
                "configdir": "/etc",
                "config_persistdir": "/var/lib/maxscale/maxscale.cnf.d",
                "module_configdir": "/etc/maxscale.modules.d",
                "piddir": "/var/run/maxscale",
                "logdir": "/var/log/maxscale",
                "langdir": "/var/lib/maxscale",
                "execdir": "/usr/bin",
                "connector_plugindir": "/var/lib/plugin",
                "threads": 4,
                "thread_stack_size": 8388608,
                "writeq_high_water": 0,
                "writeq_low_water": 0,
                "auth_connect_timeout": 3,
                "auth_read_timeout": 1,
                "auth_write_timeout": 2,
                "skip_permission_checks": false,
                "admin_auth": true,
                "admin_enabled": true,
                "admin_log_auth_failures": true,
                "admin_host": "127.0.0.1",
                "admin_port": 8989,
                "admin_ssl_key": "",
                "admin_ssl_cert": "",
                "admin_ssl_ca_cert": "",
                "passive": false,
                "query_classifier": "",
                "query_classifier_cache_size": 415775129
            },
            "version": "2.3.2",
            "commit": "1126c687a4570f60ee26a163520198a3263ccbbd",
            "started_at": "Fri, 11 Jan 2019 23:21:26 GMT",
            "activated_at": "Fri, 11 Jan 2019 23:52:42 GMT",
            "uptime": 1911
        },
        "id": "maxscale",
        "type": "maxscale"
    }
}



 Comments   
Comment by markus makela [ 2019-02-05 ]

Apart from curl what other sort of clients would you expect to find?

I think that a whole REST API tutorial might be a good way to get to know the API and how it behaves.

Comment by Geoff Montee (Inactive) [ 2019-02-11 ]

It looks like there are a ton of REST clients, but I'm not sure which are popular beyond curl.

There's a list of some here:

https://github.com/marmelab/awesome-rest#querying

Generated at Thu Feb 08 04:12:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.