Varnish Controller

API Examples

The following examples uses curl to perform some basic API tasks toward Varnish Controller. All output and input is JSON structured data.

Full Swagger API documentation can be viewed by starting the api-gw and visiting the url http://localhost:8002/docs/index.html. Host and port (localhost:8002) is where the api-gw is listening.

# Login as a system administrator using basic auth
curl -X POST -utest:test http://localhost:8002/api/v1/auth/login

# Login as a basic auth user to and existing organization 
curl -X POST -utest:test http://localhost:8002/api/v1/auth/login -d '{"org": "myorg"}'

# Get all agents
curl -H "Authorization: Bearer <access_token>" http://localhost:8002/api/v1/agents 

# Get all agents using filtering
curl -H "Authorization: Bearer <access_token>" "http://localhost:8002/api/v1/agents?name=*server*"

# Assign tags to an agent 
curl -H "Authorization: Bearer <access_token>" -X PUT http://localhost:8002/api/v1/agents/1 -d '{"Tags": [{"ID": 2}]}'

# Remove all tags from an agent 
curl -H "Authorization: Bearer <access_token>" -X PUT http://localhost:8002/api/v1/agents/1 -d '{"Tags": []}'

# Get all VCLs
curl -H "Authorization: Bearer <access_token>" http://localhost:8002/api/v1/files

# Get a specific VCL 
curl -H "Authorization: Bearer <access_token>" http://localhost:8002/api/v1/files/1

# Delete an existing VCL
curl -H "Authorization: Bearer <access_token>" -X DELETE http://localhost:8002/api/v1/files/1

# Deploy a VCLGroup
curl -H "Authorization: Bearer <access_token>" -X PUT http://localhost:8002/api/v1/vclgroups/1/deploy

# Get all API log entries
curl -H "Authorization: Bearer <access_token>" http://localhost:8002/api/v1/apilogs

# Get a new access/refresh token pair based on the refresh token
curl -X POST -H "Authorization: Refresh <refresh_token>" localhost:8002/api/v1/auth/refresh

If an error occurs for a request there will be an error structure reported back. The structure contains a Trace ID that can be used to trace the error from the API-GW all the way back to the agents. The trace ID is used in the system logs from the processes. A human readable error message is reported back and an errorKey that describes the scope of the error.


curl -H "Authorization: Bearer <access_token>" -X PUT http://localhost:8002/api/v1/vclgroups/2/deploy

{"traceId":"1coNQFLrcGkVcSXrOtfs0VtG3Ua","errorKey":"deploy","errorMsg":"id 2 not found"}%