Does anyone have sample HTML which calls REST API (using jscript) basically I am trying to create a default website on IIS and host this html page which in turn will only make a simple REST API call and return the HTTP Response status (200 on status and 400/500 error status code on failure).
Basically whenever I call this website instead of returning HTTP status code 200 I want failures to be reported when the REST API being called is returning error. Since the website is hosted on IIS and its always up and running hitting the website url will always return HTTP 200 but what I am really looking for is HTTP Response to be returned as 400/500 if the inner REST API call fails.
For instance I had written following simple HTML code but obvious it will always return HTTP 200 status (whenever URL is invoked for the website for e.g. http://localhost:2333/ as the website is up n running but I want that status to be changed to 400/500 if called REST API is failing).
<!DOCTYPE html>
<html>
<body>
<form>
Keyword:<br>
<input type="text" name="keyword" onkeyup="callREST()"><br>
</form>
<div id="response"></div>
<script>
function callREST() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("response").innerHTML = this.responseText;
}
};
xhttp.open("GET", "https://randomuser.me/api/kms", true);
xhttp.send();
}
</script>
</body>
</html>
Any simple way to achieve this to change the HTTP Response code returned (any sample?) I am trying to host this on IIS.
Thank you