Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
REST web service
Message
From
21/11/2018 15:59:16
 
 
To
20/11/2018 10:06:37
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Application:
Desktop
Miscellaneous
Thread ID:
01663216
Message ID:
01663655
Views:
83
Thank you.

>>Hello all,
>>
>>Can you provide free code so I can access a REST web service. I searched a bit and found out about Chilkat or West Wind but those are not free.
>>
>>I am using TwilioX and it works great. I guess that LibCurl could be used to access a web Service? Can anybody tell me how I could access a REST web service this way?
>
>When I have to use VFP for REST API, I prefer using Microsoft.XMLHTTP. It is very simple and have very few properties and methods (and actually making things much harder IMHO). ie:
>
>
>clear
>Local loXmlHttp As "Microsoft.XMLHTTP", lcUrl, postData,userID,id,title,body
>
>userID=12
>title="From VFP"
>body = "This is posted from VFP as a test"
>
>Text to postData textmerge noshow
>{
>  "userId":<< m.userID >>,
>  "title":"<< m.title >>",
>  "body": "<< m.body >>"
>}
>endtext
>
>lcUrl = 'https://jsonplaceholder.typicode.com'
>
>loXmlHttp = Newobject( "Microsoft.XMLHTTP" )
>loXmlHttp.Open( "POST" , m.lcUrl + '/posts', .F. )
>loXmlHttp.setRequestHeader("Content-Type","application/json; charset=UTF-8")
>loXmlHttp.Send( m.postData )
>
>? "==================================="
>? "Post Test", loXmlHttp.Status
>? loXmlHttp.responsetext
>? "==================================="
>
>MessageBox("Continue? API Codes: 200-OK, 201-Created",0,"REST API Test",10000) 
>clear
>m.id = 3
>loXmlHttp.Open( "GET" , Textmerge('<< m.lcUrl >>/posts/<< m.id >>'), .F. )
>loXmlHttp.Send( )
>
>
>? "Get post with ID X test", loXmlHttp.Status
>? loXmlHttp.responsetext
>? "==================================="
>
>MessageBox("Continue? API Codes: 200-OK, 201-Created",0,"REST API Test",10000) 
>clear
>
>loXmlHttp.Open( "GET" , Textmerge('<< m.lcUrl >>/posts/<< m.id >>/comments'), .F. )
>loXmlHttp.Send( )
>
>
>? "Get test post X comments", loXmlHttp.Status
>? loXmlHttp.responsetext
>? "==================================="
>
>
>While this simple sample and many others would be easy to construct and run using this MS XmlHTTP thing, I do and would strongly suggest using a C# active wrapper or say a Go code. Go is a great and easy to learn language, but I don't know how to embed it for VFP, so what I do is to create custom activex for my specific REST API or Web Service. Just a suggestion.
>If you need to stay within VFP, then you might do all you need using the above sample and extending it.
*******************************************************
Save a tree, eat a beaver.
Denis Chassé
Previous
Reply
Map
View

Click here to load this message in the networking platform