This is Exercise 11.3, lecture on communicating with backend, used in the course IDATA2301 Web technologies at NTNU, campus Aalesund.
The purpose of the exercise is practice sending asynchronous HTTP requests. There are several ways how to do it, you can choose any of it. The three ways shown in the lectures are:
XMLHttpRequest
, see
example here.
fetch()
function, with Promises, see
example here.
fetch()
function, with async
and
await
, see
example here.
There is an API available at
https://web-tek.ninja/php_backend/throw_a_dice.php
. It
simulates throw of a die - when you send an HTTP GET request to it, it
returns a single number in the range 1..6, representing the value of a
die. Your task is to create a simple website which utilizes the dice API.
https://web-tek.ninja/php_backend/throw_a_dice.php
<p>
element) to the page. Display a
text there: "You threw X", where X is the value you got in the response
from the API.
You can find a solution here.