Examples
banshee/examples-collection/examples/api/
backup-jobs
Example: a REST API end to end, login, token in the cache, one state per backup job.
by banshee1 installation1 version
Published on October 27, 2026. First version in this collection.
A REST API from end to end
A backup server read by its API: log in for a token, keep the token in the cache, read the list of the jobs, return one result and one duration per job.
How to read it
- The account is banshee's,
need('protocol:http:user')andneed('protocol:http:password'), set in the tree; the address is a variable of the collector. - The login is a function, called at the first pass and when the token is refused. The account goes in Basic,
user=andpassword=: the answer is then not a secret, but the token is, sosecret.markmarks it. A secret never goes into a value or a message; in the cache it is kept encrypted. - The cache keeps the token 50 minutes, under the hour it lives: the following passes do not log in again.
- A 401 means the token was refused before its time, the server having restarted: one new login, then the request again.
- One state per job:
per('job', 'Jobs'), andvalue('result', …, $job['name'])for each job of the list.
To adapt it
- An API that wants the account in a JSON body:
http.post($url, json.write(array('username' => $user, 'password' => $password)), headers=array('Content-Type' => 'application/json')). The body then carries a secret, and the whole answer is a secret by itself:secret.markis no longer needed. - Change the paths (
/api/v1/login,/api/v1/jobs) and the keys (token,jobs,last_result,last_duration) for those of your server.