AppML ASP Backend
On Windows-hosted sites, classic ASP takes the same action-handler role that PHP plays elsewhere: it receives AppML's list, insert, update, and delete requests and executes them against the server's database.
ASP as the Action Handler
A classic ASP file, written in VBScript, plays the same role as a PHP handler: it reads the requested action, connects to a database - typically through ADODB and a driver for SQL Server or Access - runs the matching query, and writes a JSON response back to the page.
- Uses an ADODB.Connection object instead of mysqli or PDO
- Branches on the requested action with a VBScript Select Case block
- Reads list requests from Request.QueryString and posted values from Request.Form
- Builds its JSON response by writing text directly with Response.Write, since classic ASP has no built-in JSON encoder
A minimal ASP action handler
<%
Response.ContentType = "application/json"
Dim action, conn, rs
action = Request.QueryString("action")
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;Data Source=.;Initial Catalog=HyringLearn;Integrated Security=SSPI;"
Select Case action
Case "list"
Set rs = conn.Execute("SELECT id, firstname, lastname, department FROM employees ORDER BY lastname")
Response.Write "{""records"":["
Dim first
first = True
Do While Not rs.EOF
If Not first Then Response.Write ","
Response.Write "{""firstname"":""" & rs("firstname") & """,""lastname"":""" & rs("lastname") & """}"
first = False
rs.MoveNext
Loop
Response.Write "]}"
rs.Close
Case "insert"
conn.Execute "INSERT INTO employees (firstname, lastname, department) VALUES ('" & Request.Form("firstname") & "', '" & Request.Form("lastname") & "', '" & Request.Form("department") & "')"
Response.Write "{""success"":true}"
Case Else
Response.Write "{""error"":""Unknown action""}"
End Select
conn.Close
%>Request parameters arrive through Request.QueryString for GET-style list requests and Request.Form for posted insert or update values, mirroring the role $_GET and $_POST play in a PHP handler.
Classic ASP is an older, Windows-specific technology. AppML's ASP examples reflect the era the framework was written for rather than being a recommendation of ASP over PHP for new projects today.
Exercise: AppML Server Backends
What role does a server backend play in a full AppML CRUD app?