An API is really just methods that you publicly expose. Say, for example, you have a blog site. You want your members to be able to post a blog entry without actually coming to your site - logging in, filling out a form, etc..
Perhaps they want to create an Android/IPhone app to post to your cool blog site. You can allow them to do that.
Create an API for this:
<?php
function createBlogEntry(memberEmailAddress, memberPassWord, BlogTitle, BlogBody)
{
//Here you would usually call an internal (or not publicly exposed) method that
//contains the actual logic to insert. Like Jim's answer states, you just want
//people to be able to performan action in your system, you don't want them to see HOW you do it.
encapsulatedBlogCreation(memberEmailAddress, memberPassWord, BlogTitle, BlogBody);
//This is where API's get tricky. I need to return to the user the result of
// the save so that my user knows what happens. In my API documentation, I
//tellthe user 0 = Created Successfully. If this is a READ operation
//just return the result. Most modern programming languages also have
//a way to capture an HTTP response - so dealing with the return is their responsibility
return 0;
}
?>
A couple things:
- In my API, I didn't need a developer Key, I allowed the user to pass in their login credentials. An API key does the same thing, it uniquely identifies a request and links it to a user in the system.
- This API doesn't use XML. This is about as simple as an api gets. This can be called by sending an HTTP request which can be done with any modern programming language. Say I put the above code in a file called blog.php and put it in the root of my blogsite. I would call it like:
*http://myblogsite.com/blog.php?memberEmailAddress=myEmal@example.com&memberPassWord=myPass&BlogTitle=Title-of-post&BlogBody=the_blog_post_is_here*
One thing you need to understand, is that there has to be a need for an API. You can expose a method to create a blog entry, but if no one knows about it or uses it - it's worthless. API's need to be documented, advertised, and provide a benefit to potential users.