Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing a REST web service in VFP8... 1

Status
Not open for further replies.

Neil Toulouse

Programmer
Mar 18, 2002
882
GB
Hi Guys

Is it possible to access a REST web service in VFP8 without any additional add-ons?

I had the (mis)understanding you could pass the call as a URI so would be fairly straight forward task, but I am going round in circles and getting nowhere!

Can anyone point me in the right direction?

If building a URL is the right way to go, how would I turn this info into a URI:

url: mydomain.co.uk/Authentication/Authenticate
type: GET
header:
name: “X-CustomerToken”,
value: “{your API key}”


Many thanks
Neil



I like work. It fascinates me. I can sit and look at it for hours...
 
URI is just one part of a API request, we are in the schema of HTTP protocol, where the URI is just one part, you send a header and body to a URI as a certain request type, so the URI is just one part of it.

You spec is not very clear. Could be interpreted as an empty header and a body containing a name and value, could also describe the header itself consisting of a name-value pair with name being X-CustomerToken and your API key as value, which sounds more plausble.

This means the header to set is
Code:
X-CustomerToken:{your API key}

You can use the comfort of the XMLHTTP class, which you find described in samples here in other forum threads.

Code:
#Define clAsync .F.
#Define ccAPIKey '{your API key}'
loRequest = Createobject('MsXml2.XmlHttp')
loRequest.SetRequestHeader('X-CustomerToken',ccAPIKey)
loRequest.Open("GET","mydomain.co.uk/Authentication/Authenticate", clAsync)
? loRequest.Status
? loRequest.ResponseText

If you want more comprehensive samples, take a look at my on hold projects
[URL unfurl="true"]http://vfpoauth.codeplex.com[/url]
and
[URL unfurl="true"]http://vfptweetapi.codeplex.com[/url]

vfpoauth actually is a part of vfptweetapi having a broder purpose for any API needing OAuth type of authentication.

Bye, Olaf.
 
I forgot one important line actually sending the request. Without this you can't get a response, of course.

Code:
#Define clAsync .F.
#Define ccAPIKey '{your API key}'
loRequest = Createobject('MsXml2.XmlHttp')
loRequest.SetRequestHeader('X-CustomerToken',ccAPIKey)
loRequest.Open("GET","mydomain.co.uk/Authentication/Authenticate", clAsync)
[COLOR=#A40000]loRequest.Send()[/color]
? loRequest.Status
? loRequest.ResponseText

Bye, Olaf.
 
...and one more error: you can only set a request header, after the request has been opened, so switch lines 4 and 5.

Bye, Olaf.
 
Thanks Olaf :)

The spec I was given was not very clear and communication with them was just leaving me more confused! And have just found out a few minutes ago that they have realised their documentation is wrong anyway!

Anyway, thanks to your info I have a way forward.

Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top