Httprelay Proxy JSON example
by Jonas Jasas
HTML
<h1>JSON example</h1>
<h2><a href="https://httprelay.io/" target="_blank">HTTP Relay</a> proxy communication method</h2>
<p>
This example ilustrates action with the JSON response.
</p>
<p>
Copy this link and paste it in to the new browser tab to see the result:
<div id="serverLink" href="" target="_blank">
<span class="proxy-url" id ="proxyUrl"></span><span class="proxy-server" id="proxyServer"></span><span class="proxy-path" id ="proxyPath"></span>
</div>
</p>
<details>
<summary>URL legend</summary>
<ul>
<li class="proxy-url">URL of HTTP Relay proxy communication method</li>
<li class="proxy-server">Server name</li>
<li class="proxy-path">Path</li>
</ul>
</details>
CSS
.proxy-url {
color: blue;
}
.proxy-server {
color: green;
}
.proxy-path {
color: red;
}
JavaScript
//import Httprelay from 'https://cdn.httprelay.io/httprelay-proxy-v1.js'
import Httprelay from 'https://www-namai.jon.lt/httprelay/public/httprelay-proxy.js'
// Creating random name server
let httprelay = new Httprelay()
// Registering handler for the path
httprelay.get('/time', function() {
debugger
let today = new Date();
return {
year: today.getFullYear(),
month: today.getMonth(),
day: today.getDate(),
time: `${today.getHours()}:${today.getMinutes()}:${today.getSeconds()}`
}
})
// Starting server
httprelay.start()
// NOT IMPORTANT ///////////////////////////////////////////////////////////////////////////////
document.getElementById('proxyUrl').innerHTML = httprelay.proxyUrl + '/';
document.getElementById('proxyServer').innerHTML = httprelay.serverId;
document.getElementById('proxyPath').innerHTML = httprelay.routes[0].path;