简体   繁体   中英

Setting up REST API on IIS using ASP Classic / JScript

I need to expose existing API as REST to outside world, for some internal reasons I decided to go with IIS8 + ASP Classic + JScript. I succeeded setting up IIS for ASP Classic and to form JSON response with JScript (the hack with HTMLFile helped significantly here). It appears I need for every exposed resource one separate ASP page (JSCript code), but it's not clear to me how to set up redirects to reach appropriate ASP when accessing particular resource, eg

accessing http://server/some-resources/123 should be redirected to ASP 'some-resources.asp', while I need to get the original URL in JScript, call the backend and respond with content of the some-resource with id=123

and similarly, for http://server/other-resources it should access ASP 'other-resources.asp' and respond with collection of other-resources (possibly with some paging mechanism). So the questions are

  • is this basic concept of "ASP per resource" a good idea at all, or is there another "standard"?
  • if yes, how to set the IIS redirects to access appropriate ASP for any URL appropriate to this resource (single resource, collection, ...)

You should be able to write rewrite rules in IIS to direct http://server/resource/123 to http://server/resource.asp?id=123. Or you could put all your code in one giant ASP file and redirect to http://server/onegiantaspfile.asp?res=resource&id=123, again using rewrite rules.

I've also done this by working magic in the 404 handler but in the long run I found that to be fragile. It absolutely works but it's kind of non-standard. Nevertheless I had a web app that worked this way for 15 years with just a little maintenance as we ported it from server to server and from Window Server version to Windows Server version. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM