Reputation: 119
I have the following tag in my HTML:
<h3>Current Track: {title} </h3>
I would like to fill the {title} part with the result's array "state" of a REST call that looks like this:
https://username:[email protected]:443/rest/items/Title
I've tested the outcome with Postman and got the following result:
{
"link": "https://my.openhab.org/rest/items/Title",
"state": "Giles",
"type": "String",
"name": "Title",
"tags": [],
"groupNames": []
}
How do I achive this? The rest call contains login credentials.
EDIT:
I have created a PHP file named openhab.php:
<?php
function getStatus($item)
{
$url = "https://user:[email protected]:443/rest/items/" . $item;
$options = array(
'http' => array(
'header' => "Content-type: text/plain\r\n",
'method' => 'GET',
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
getStatus("Title");
?>
What would the html tag look like?
Upvotes: 0
Views: 543
Reputation: 21
It is not simply done with only HTML. You can use PHP or Javascript, for example, in order to retrieve the result from the API call. Postman is very helpful with this, as it can create the required code (for the API call) for you.
If you use javascript: wrap the title in a HTML tag, such as a span, and add an ID to it. Then target the element by ID with javascript (document.getElementById(id)) and change the value.
If you use PHP: The result will be stored in a variable. You show store the "state" into a new variable. Then use "echo" (example with variable $state: ) to display the value in html.
I suggest you get some basic knowledge about PHP or Javascript, depending on which one you want use.
Upvotes: 1