API stands for application programming interface. A no of definition and explanation is available on wiki here. But the simpler example, I would give you is 3 pin electric plug, we all see in our home. The plug is basically, an interface to the electricity supply we are getting. We did’nt have to go into what going behind the plug like how the circuit is made,how the current is circulated, how it is produced etc. The interface user, like freeze, tv, radio etc simply connect to the plug and start getting the electricity. I have created a Sample API in this post
In the same, way in programming (system or software or hardware) we create an interface, so that other can use it. Infact, someone has said that a program without API is like a house without any door or window. Your application will become popular only by interacting with the outside world. Great example of this is Facebook and Twitter. Facebook has provide a no of API to retrieve its feeds, do signin, signup etc. It is upto you how much functionality, you want to expose to the outer world.
In Web development, API deals with handling request from outside the application and returning back a response to the requesting client. The request and response structure is predefined by API developer. The response is generally data in xml or json formate. Below lines I have taken from wiki, which add to my point
Now, I will give an example of API from one of my project, I have used it
We are working on digitising, documentation process for Applying loan with a bank . Due, to security risk, the bank can’t give us access to there database. But to implement our functionality, we need all the document associated with a loan, which we can put before the user to sign online. Thus our functionality will trigger once we have the document.
The client proposed the below scheme
-> User will login to the Bank portal with credential registered with the bank
-> He will see the loan he has applied for and also the list of document to be signed. when he will click on Sign Button, he will be redirected to my site with his user_id and loan_id
-> Using the user_id and loan_id, my application will made a API call to say the below dummy url
They are expecting xml request. So, The request body, should have below structure.
-> They also provided detail of security header i,e username, password, secret token etc each request should contain in order to connect to their API
-> When request will be successful, we will get all the document detail in response in XML formate. They also told us detail of the response i,e at what xml nodes, the required data will be present.
Summary of Web API usage:
-> You should know the url to which you need to make the call
-> You should have access token detail as used by the API to make conection to it
-> Your request body should be in formate as defined by the API and carry all the required parameter
-> You should be able to handle the returned response.