<h1>
Interview Question 2
</h1>
<blockquote>
We have an HTTP client (here <code>http</code>) to fetch resources from our API.
Knowing the server is stateless and :
<ul>
<li id="/api/v1/books"><code>/api/v1/books</code> usually takes
<select class="secs"><option selected>1</option><option>2</option><option>3</option></select>seconds
to <select class="status"><option selected>succeed</option><option>fail</option></select>
</li>
<li id="/api/v1/authors"><code>/api/v1/authors</code> usually takes
<select class="secs"><option>1</option><option>2</option><option selected>3</option></select>seconds
to <select class="status"><option selected>succeed</option><option>fail</option></select>
</li>
<li id="/api/v1/libraries"><code>/api/v1/libraries</code> usually takes
<select class="secs"><option>1</option><option selected>2</option><option>3</option></select>seconds
to <select class="status"><option selected>succeed</option><option>fail</option></select>
</li>
</ul>
Focus on the <code>request</code> function and answer the following questions :
<ol>
<li>How much time does the <code>request</code> function need to complete ?</li>
<li>Can we improve the <code>request</code> function ?</li>
<li>Can you explain the error handling, can it be improved ?</li>
</ol>
Feel free to express your thoughts openly and elaborate on your reasoning.
</blockquote>
<script>
const el = document.createElement.bind(document)
const tx = document.createTextNode.bind(document)
function output (msg) {
const line = el('div')
const timestamp = line.appendChild(el('span'))
timestamp.className = 'timestamp'
const now = new Date()
const z = n => n.toString().padStart(2, '0')
timestamp.appendChild(tx(`${z(now.getHours())}:${z(now.getMinutes())}:${z(now.getSeconds())}`))
const message = line.appendChild(el('span'))
message.className = 'message'
...