Examples
banshee/examples-collection/examples/protocols/
http-get-headers
Example: http.get with headers=, and the headers of the answer; an API that answers JSON.
by banshee1 installation1 version
Published on October 27, 2026. First version in this collection.
// http.get with headers: send headers with the request with headers=, and read the headers of the answer.
// The collector checks that an API answers in JSON.
need('protocol:http');
$url = variable('example:api:url', 'text', array(
'label' => 'Address of the API',
'help' => 'For example https://api.example/v1/status.',
));
output('content-type', 'text', array('label' => 'Type of the answer'));
watch.expect('not-json', 'API not answering JSON', 'content-type', array('warning' => array('application/json')));
$answer = http.get($url, headers=array('Accept' => 'application/json', 'Cache-Control' => 'no-cache'));
// The headers of the answer: each name in lowercase, a header sent twice joined by ", ".
$type = list.get($answer['headers'], 'content-type', 'none');
// "application/json; charset=utf-8": the part before the ; only.
$parts = text.split($type, ';');
value('content-type', text.trim($parts[0]));