logo

About userlists

REST API


Start with v3.6 HAProxy-WI begun support REST API:
curl -X POST \
  https://demo.haproxy-wi.org/api/ \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: 0' \
  -H 'Host: demo.haproxy-wi.org' \
  -H 'User-Agent: PostmanRuntime/7.19.0' \
  -H 'cache-control: no-cache' \
  -H 'login: admin' \
  -H 'password: admin'
		
Will give you:
{
"help": {
    "server/<id,hostname,ip>/runtime": "exec HAProxy runtime commands 
        by id or hostname or ip",
    "server/<id,hostname,ip>/backends':'show backends 
        by id or hostname or ip",
    "server/<id,hostname,ip>/action/stop": "stop HAProxy service 
        by id or hostname or ip",
    "servers": "show info about all servers",
    "server/<id,hostname,ip>": "show info about server 
        by id or hostname or ip",
    "server/<id,hostname,ip>/action/restart": "restart HAProxy service 
        by id or hostname or ip",
    "server/<id,hostname,ip>/action/start": "start HAProxy service 
        by id or hostname or ip",
    "server/<id,hostname,ip>/status": "show HAProxy status 
        by id or hostname or ip",
    'server/<id,hostname,ip>/config/get':'get HAProxy config from 
        the server by id or hostname or ip',
    'server/<id,hostname,ip>/config/send':'send HAProxy config 
        to the server by id or hostname or ip. Has to have config header 
        with config and action header for action after upload. 
        Action header accepts next value: save, test, reload and restart. 
        May be empty for just save',
    'server/<id,hostname,ip>/config/add':'add section to the HAProxy config 
        by id or hostname or ip. Has to have config header with section 
        and action header for action after upload. Action header accepts 
        next value: save, test, reload and restart. May be empty for just save'
    }
}
		
For example you can stop certain HAProxy service:
curl -X POST \
  https://demo.haproxy-wi.org/api/server/1/action/stop \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: 0' \
  -H 'Host: demo.haproxy-wi.org' \
  -H 'User-Agent: PostmanRuntime/7.19.0' \
  -H 'cache-control: no-cache' \
  -H 'login: admin' \
  -H 'password: admin'
		
Will give you:
{
    "status": {
        "status": "done",
        "ip": "178.57.218.185",
        "id": 1,
        "hostname": "test-server",
        "action": "stop"
    }
}
		

How to upload a new config and after restart HAProxy service:
curl -X POST \
  https://demo.haproxy-wi.org/api/server/test-server/config/send \

  -H 'cache-control: no-cache' \
  -H 'login: admin' \
  -H 'password: admin' \
  -d 'global
    log         127.0.0.1 local2
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats
    stats socket *:1999 level admin
    stats socket /var/run/haproxy.sock mode 600 level admin
    server-state-file /etc/haproxy/haproxy.state

defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
	...'
		
Will give you:
{
    "config": {
        "test-server": "config was uploaded"
    }
}