While there's not much available detailing what happens on the server side of a Rest API written in VBScript, there is one article that addresses this issue: Can I build a REST application using ASP Classic?. The bulk of that post describes various issues regarding JSON stringifying as well as acquiring data from a database. My question concerns neither of these. But ignoring these (and a few syntax errors), there is very little else in that post.
So, I admit to being very much of a novice regarding server-side behaviour. But when I strip away everything from the above-mentioned post, I am left with a quite bare few lines of code that appear to simply request an input value and then output a string. So I wondered if this is indeed all that is involved in the bare-bones I/O (i.e., ignoring the security and formatting issues). I decided to try this out. My results are puzzling. When I call this incredibly simple API, instead of receiving the very simple JSON string that is being sent, I instead get back the entire piece of source code comprising the API, from the opening HTML tag to its closure. I've obviously made a very fundamental error.
Here is my code. First, here is the extremely bare-bones REST API itself (please note: this is ONLY writing back an artificial JSON string. It's not even concerning itself with receiving the POST parameters.) This is "simplerest.asp"
<html>
<head>
</head>
<body>
<%
Response.Write("{" & Chr(34) & "SomeCert" & Chr(34) & ":" & Chr(34) & "12345"& Chr(34) & "}")
%>
</body>
</html>
And here is the code (utilizing jQuery) to call this "API" (testrest.asp):
<html>
<head>
<script type="text/javascript" src="/./include/jquery-3.4.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
function getCert(certNumber)
{
var settings = {
"async": true,
"crossDomain": true,
"url": "example.com/simplerest.asp",
"method": "GET",
"success": function (response) {
alert("success");
},
"headers": {
"Accept": "application/json"
}
}
$.ajax(settings).done(function (response) {
certvals = response;
alert("certvals is " + certvals);
});
}
getCert("dummy");
</script>
</body>
</html>
As I stated above, when I run the calling logic, what is returned in certvals
is the precise ASCII representation of the entire "API" code. In the spirit of what I am attempting, which is to see an API running in its most elementary mode, can someone enlighten me as to what dumb error I am making?