Tutorials

Manage frontends

In your load balancer configuration, a frontend section defines the client-facing proxy that receives requests.

You can manage frontends programmatically via the API endpoint /services/haproxy/configuration/frontends.

Note

The version parameter in DELETE, POST, and PUT requests must match the system’s current version. The examples in this section use a GET request to /v2/services/haproxy/configuration/version to retrieve the version and populate the CFGVER environment variable for the URL version parameter.

List frontends Jump to heading

To get a list of frontends, make a GET request to the frontends endpoint:

bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends"
bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends"
output
json
{
"_version":1,
"data":[{
"default_backend":"webservers",
"name":"fe_main"
}]
}
output
json
{
"_version":1,
"data":[{
"default_backend":"webservers",
"name":"fe_main"
}]
}

List a specific frontend Jump to heading

To get information about a specific frontend, add its name to end of the URL path. Below, we view information for the frontend named myfrontend:

bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend"
bash
curl -X GET \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend"
output
json
{
"_version":2,
"data":{
"default_backend":"webservers",
"maxconn":2000,
"mode":"http",
"name":"myfrontend"
}
}
output
json
{
"_version":2,
"data":{
"default_backend":"webservers",
"maxconn":2000,
"mode":"http",
"name":"myfrontend"
}
}

Add a frontend Jump to heading

To add a frontend, make a POST request to the frontends endpoint. Send the fields to set in the body of the request. Below, we create a new frontend named myfrontend.

bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X POST \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "myfrontend",
"mode": "http",
"default_backend": "webservers",
"maxconn": 2000
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends?version=$CFGVER"
bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X POST \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "myfrontend",
"mode": "http",
"default_backend": "webservers",
"maxconn": 2000
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends?version=$CFGVER"

Replace a frontend Jump to heading

To make changes to a frontend, you must replace it entirely. To replace an existing frontend, make a PUT request to the frontends endpoint, passing the name of the frontend at the end of the URL path:

bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X PUT \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "myfrontend",
"mode": "tcp",
"default_backend":
"webservers",
"maxconn": 1000
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend?version=$CFGVER"
bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X PUT \
--user admin:adminpwd \
-H "Content-Type: application/json" \
-d '{
"name": "myfrontend",
"mode": "tcp",
"default_backend":
"webservers",
"maxconn": 1000
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend?version=$CFGVER"

Delete a frontend Jump to heading

To delete a frontend, use the DELETE method:

bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X DELETE \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend?version=$CFGVER"
bash
CFGVER=$(curl -s -u admin:adminpass http://localhost:5555/v2/services/haproxy/configuration/version)
curl -X DELETE \
--user admin:adminpwd \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/frontends/myfrontend?version=$CFGVER"

If this page was useful, please, Leave the feedback.