Page 1 of 1

Hooking appery.io with ActiveVFP and JSON REST controller

Posted: Thu Jul 25, 2013 2:31 am
by abigdreamer

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
    ENDPROC

    PROCEDURE infoAction
    RETURN "homeFolder: " + THIS.homeFolder + ""
    ENDPROC

    PROCEDURE 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
    ENDPROC

    PROCEDURE 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
    ENDPROC

    PROCEDURE 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
    ENDPROC

    PROCEDURE 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_Name

    oJSON.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


Hooking appery.io with ActiveVFP and JSON REST controller

Posted: Thu Jul 25, 2013 2:37 am
by maxkatz

When I click on:

http://68.100.149.95:444/avfp6/customers

I get an HTML page, not JSON (unless it applies a UI template when viewed from a browser)


Hooking appery.io with ActiveVFP and JSON REST controller

Posted: Thu Jul 25, 2013 3:01 am
by abigdreamer

Hooking appery.io with ActiveVFP and JSON REST controller

Posted: Thu Jul 25, 2013 3:18 am
by maxkatz

Yes .