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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is an API? 1

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
hello guys... may somebody explain what is an API, where can you use it in VFP? Can it be used in VFP for certain projects? thanks
 
An API is a published or unpublished Applications Programming Interface, usually a way to execute actions on a (often) remote device using a set of predefined protocols.

For example, google publish an API for their mapping application to enable people to reach out and ask for the distance between two points, recently on here we have had someone trying
to use the WhatsApp API to send messages, images and the like.

VFP can be programmed to use an API and can offer an API if you develop one, if you have a VFP app you might think of the parameters you pass to it as an API, for example calling it with the path to the database you want to use - maybe allowing an action to be taken too, such as Packing or reindexing or something.

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Well, the letters stand for Application Programming (or sometimes Programmers') Interface. It is essentially a mechanism that allows a program to interact with some other software in some way. For example, Windows has an API that lets programmers call certain functions connected with Windows, such as locating the current active window or finding out what printers are installed. Visual FoxPro can access that API, as can many other languages.

I could probably give you a better answer if you explained what you are trying to achieve. What do you want to do within your VFP rpoject that you think an API might be able to help with?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
As Griff and Mike already explained what API stands for, you might have noticed that you have already created you own internal APIs, though they might not be called API but CPI (where the 'C' stands for Class), or FPI (where 'F' stands for Function). Well, you name it :)

Mostly those internal interfaces are only used by yourself and most of all they are by all means 'small'. However, as soon as you create a class or a prg filled with reusable functions this small concept is elevated to a higher rank. Reusable classes and functions need an interface that you can use even after a longer time of not using it. For beginners this is something really hard to achieve because of lack of experience. This isn't bad but often leads to complete redesigns of old libraries and this well... often leads to new interfaces and reprogramming of an old app.

That's the reason, why many APIs exist in different versions which means: Never replace an old API by a new one. Keep the old API and create a new version of it within a new library. That way, an app that uses the older version can be changed in other parts without having to change the old interface and new apps simply make use of the new API version.

HTH

-Tom
 
Indeed, as Mike already mentioned, Windows OS Functions are also called an API, it's an atypical API, but when you look into the IntelliSense tip coming up when you write DECLARE in a code window you'll see the keyword WIN32API.

If you look at it from the right perspective the base principle is the same as with all APIs - they provide functionalities related to something. Today often related to a website, in a form that
a) offers more or less the same functionality as the site itself - the similarity of Windows here is the WIN32API offers functions about windows, from such basic tasks as allocating RAM memory to listing Drives.
b) offers data in a more raw form than the way it's embedded in the human-readable form a browser renders from HTML - the similarity of Windows here is that an end-user finds a list of drives in the Windows Explorer, but when you RUN /N explorer.exe from VFP (which works this way) you wouldn't want to make a Screenshot of the Window and then use OCR (optical character recognition) to get the list of drives and partitions. Instead you make a call of GetLogicalDrives.
c) often is limited to a certain number of requests and requires you to register as an API user - which has no correspondence in Windows. The Win32API is free, you alreeady paid for it by buying Windows. MS earns from it as this enables programmers to concentrate on the core of your application functionalities without needing to get down to low level functions. Even though allocating RAM is an example of such a low level task of a program.



Chriss
 
To give you another example, Mandy ...

In another thread, you asked how to animate an image. The solution I suggested involved using this function:

Code:
Sleep(100)

The Sleep() function does not exist in VFP, nor is there anything in VFP that does exactly the same thing. But it is available as part of the Windows API. So this is an example of using a Windows API function within your VFP program.

In general, for a VFP program to be able to call an API function, it first has to "declare" it. This is so that VFP knows what parameters to pass and what data type to return. You do that via the DECLARE command, which in this example is as follows:

Code:
DECLARE Sleep IN WIN32API INTEGER iPeriod

Note the keyword WIN32API in the above statement. That tells VFP that this is the Windows API. APIs from other software work in much the same way.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
thanks for all you answers.... I appreciate so much... Mike, i wanted to put into my app the sending of sms using but i do not where to start... if ou could remember i have created an app that will send an sms using gsm modem... now i'm trying to study how to integrate the API... i do not know if i have understood it correctly... thanks....
 
I see, the starting point for developers is here:
The usage is, as I said is typical for today's APIs about services like sending SMS, via the internet, via HTTP-Requests.
VFP has no direct command or function for it, but you can use several OLE classes for making such requests. I'll stop here, as it is a vast topic and I don't want to overwhelm you. Plus, I'm off for lunch... Maybe later.


Chriss
 
Mandy, I'm afraid I can't help you with the Wavecell API. Every product that has an API is different, and I have no knowledge of Wavecell's. Glancing at their documentation, it looks like a fairly complex system. Your best bet would be to try to find a Wavecell support forum of some kind, although I can't see anything like that on Wavecell's own site.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
some years ago I tried to explain on my blog how ReST services work. It was a 7-part series and the offered translation by *goggles* isn't that bad at all.
Perhaps it might help, to read it.
Have a look here: [URL unfurl="true"]https://tomsvfpblog.blogspot.com/2018/10/vfp-das-web-und-der-ganze-rest.html[/url]
There's a selector for translations on the right side.

-Tom
 
To give you a starting point, here's how HTTP requests, the base for this API, works in VFP:

Code:
LOCAL loHTTP

loHTTP = CreateObject("Msxml2.ServerXMLHTTP.6.0")
loHTTP.open("GET", "[URL unfurl="true"]http://example.com/",.t.)[/URL]
loHTTP.send()

DO WHILE loHTTP.readyState<>4
   DOEVENTS 
ENDDO 

? loHTTP.getAllResponseHeaders()
? loHTTP.responseText()

In this case, the responsetext is HTML of the web page In the Wavecell API the request must be a POST request, some headers must be set, for which you can use loHTTP.setRequestHeader() and the loHTTP.send(body) will send the data you need to post.

I just want to show, that you might get to your goal faster than you think. But you need to get the details about this from the developer documentation at For example, to send a single SMS:
You'll need to have an account to get the necessary values for using the API.

Chriss
 
Thanks so much Mike... I have always been a recipient of your big and substantial advises and help.... Hi Chris... i really want to extend my knowledge with VFP9. The app that i made is actually every employee that will log in to it will receive a text/sms message... now that i have that... I want to use wavecell api so that wavcell will send a text/sms intead of the gsm modem... thanks chris.... god bless....
 
Mandy said:
I want to use wavecell api so that wavcell will send a text/sms intead of the gsm modem... thanks chris.... god bless....
In principle that works.

I have never used the GSM Modem way to connect to a mobile and use it. I think this will just have the usual SMS costs, depending on your plan several SMS might be free per month. Wavecell API has costs, as they explain at
Plus, you'll need to get into the details of that API.



Chriss
 
Thanks Jonathan... i am still studying API because i want to use wavecell in my program in sending SMS. I hope its possible...
 
Hello Mandy,

if you are not forced to use wavecell you may use an "SMS provider".
Many of them offer to just send a formatted email , like subject with target number, access key,...

So if your program can send email it can send SMS.
Some of them allow a "dialogue" so the user can press answer and you get a mail with ID fpr identification back.

Its easy and maybe cheaper (usually you buy an amount like 1.000 SMS or 10.000,...)

Regards
tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top