Hooking appery.io with ActiveVFP and JSON REST controller
This link returns JSON from a FoxPro database
http://68.100.149.95:444/avfp6/customers
It has things like VFP controller Code
It has a few other links you can click on.
I just don't understand how to HOOK this to Appery.io
Its very important for the Visual FoxPro Community.
customers.prg -Customers Controller
* bypasses Main.prg and .AVFP script code
*
DEFINE CLASS customersController AS restController
*
PROCEDURE openData
SELECT 0
USE (THIS.homeFolder + "customers.dbf") ALIAS customers
ENDPROCPROCEDURE infoAction
RETURN "homeFolder: " + THIS.homeFolder + ""
ENDPROCPROCEDURE getAction
LOCAL cCustId
cCustId = THIS.Params[1]
THIS.openData()
SELECT CUSTOMERS
LOCATE FOR custId = cCustId
IF FOUND()
LOCAL cJSON
**USE mydbf &&test error
*quick and dirty JSON
cJSON = [{"custId":"] + RTRIM(custId) + [","custName":"] + RTRIM(custName) + [",] + ;
["custStat":"] + RTRIM(custStat) + ["}]
RETURN cJSON
ENDIF
ENDPROCPROCEDURE listAction
LOCAL cHTML
cHTML = ""
*oEmp=newOBJECT('schedbizobj','c:\avfp5.61Demo\prg\utiltest2.prg')
SET PROC to substr(oProp.AppStartPath,1,AT([\],oProp.AppStartPath,2))+'prg\AVFPutilities' ADDITIVE && Make sure you use ADDITIVE or bad things happen!
THIS.openData()
SELECT CUSTOMERS
cHTML= oHTML.mergescript(FILETOSTR(substr(oProp.AppStartPath,1,AT([\],oProp.AppStartPath,2))+'viewtest.avfp'))
RETURN cHTML
ENDPROCPROCEDURE helloworld && custom method
LOCAL cHTML
cHTML = ""
*USE mydbf
*SET PROC to substr(oProp.AppStartPath,1,AT([\],oProp.AppStartPath,2))+'prg\AVFPutilities' ADDITIVE && Make sure you use ADDITIVE or bad things happen!
cHTML= oHTML.mergescript(FILETOSTR(substr(oProp.AppStartPath,1,AT([\],oProp.AppStartPath,2))+'hello.avfp'))
RETURN cHTML
ENDPROCPROCEDURE getemployees && custom method
oJSON=NEWOBJECT('json','json.prg')
SET PATH TO oProp.AppStartPath+'data\AVFPdemo41\'
select e.emp_id as id, e.first_Name as firstName, e.last_Name as lastName, e.title as title, [images/Emps/]+e.picture as picture,count(r.emp_id) as reportCount ;
from employee e left join employee r on VAL(r.reports_to) = VAL(e.emp_id) ;
INTO Cursor SearchResults;
group by e.last_Name,e.emp_id, e.first_Name,e.title, e.picture ;
order by e.last_Name,e.first_NameoJSON.keyforcursors="items"
send JSON data and properties back
oResponse.ContentType = "application/json;charset=utf-8"
oResponse.Write(oJSON.stringify('SearchResults'))
oResponse.Flush
lcHTMLout=[]
ENDPROC
************************************************************************
ENDDEFINE