Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Created February 21, 2022 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haproxytechblog/0a032b443fc610b8bd9848c8c57af96f to your computer and use it in GitHub Desktop.
Save haproxytechblog/0a032b443fc610b8bd9848c8c57af96f to your computer and use it in GitHub Desktop.
Announcing HAProxy Data Plane API 2.5
$ curl -X PUT \
-–user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "test",
"mode": "http",
"http-check": {
"type": "expect",
"match": "status",
"pattern": "200,201,300-310"
}
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/backends/test?transaction_id=a7c318c3-03db-41cf-9568-96b36ffcc228"
backend test
mode http
http-check expect status 200,201,300-310
backend test
mode http
http-check connect
http-check send meth GET uri /health ver HTTP/1.1 hdr host test.com
http-check expect status 200-399
$ curl -X POST \
--user admin:password \
-H "Content-Type: application/json" \
-d '{
"index": 0,
"type": "connect"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/http_checks?parent_name=test&parent_type=backend?transaction_id=a7c318c3-03db-41cf-9568-96b36ffcc228"
$ curl -X POST \
--user admin:password \
-H "Content-Type: application/json" \
-d '{
"index": 1,
"type": "send",
"method": "GET",
"uri": "/health",
"version": "HTTP/1.1",
"headers": [
{
"name": "host",
"fmt": "test.com"
}
]
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/http_checks?parent_name=test&parent_type=backend?transaction_id=a7c318c3-03db-41cf-9568-96b36ffcc228"
$ curl -X POST \
--user admin:password \
-H "Content-Type: application/json" \
-d '{
"index": 2,
"type": "expect",
"match": "status",
"pattern": "200,201,300-310"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/http_checks?parent_name=test&parent_type=backend?transaction_id=a7c318c3-03db-41cf-9568-96b36ffcc228"
$ curl -X POST \
--user admin:password \
-H "Content-Type: application/json" \
-d '{
"name": "mycache",
"total_max_size": 4095,
"max_object_size": 10000,
"max_age": 30
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/caches"
cache mycache
total-max-size 4095
max-object-size 10000
max-age 30
$ curl -X POST \
--user admin:password \
-H "Content-Type: application/json" \
-d '{
"index": 0,
"type": "cache",
"cache_name": "mycache"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/filters?parent_name=webservers&parent_type=backend&transaction_id=c9391070-db48-478c-bce3-7c1e0759dd68"
$ curl -X POST \
--user admin:password \
-H "Content-Type: application/json" \
-d '{
"index": 0,
"type": "cache-store",
"cache_name": "mycache"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/http_response_rules?parent_name=webservers&parent_type=backend&transaction_id=c9391070-db48-478c-bce3-7c1e0759dd68"
$ curl -X POST \
--user admin:password \
-H "Content-Type: application/json" \
-d '{
"index": 0,
"type": "cache-use",
"cache_name": "mycache"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/http_request_rules?parent_name=webservers&parent_type=backend&transaction_id=c9391070-db48-478c-bce3-7c1e0759dd68"
$ curl -X POST \
--user admin:password \
-H "Content-Type: application/json" \
-d '{
"index": 0,
"length": 1000,
"type": "request"
}' \
"http://127.0.0.1:5555/v2/services/haproxy/configuration/captures?frontend=test&transaction_id=c9391070-db48-478c-bce3-7c1e0759dd68"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment