Hi All,
Hope all is well.
So here’s the situation, I think I’ve thought of everything and I think its all going to go according to plan and then boom I realise I don’t have an API for my new website/social network called Add Deal Babies. My website is due to go live this week… however… I need to develop an API for the website so that the mobile app that I am looking to get designed will be able to communicate to the website.
The website has been written in PHP with a MYSQL backend.
I’ve never created my own API before and I am looking for some advice on where to start. What do I need?? How does it all work?
If anyone has any experience of this I want to hear from you.
Well technically you already made an API…When viewing a deal (i guess?) for example you might have a URL like /view/this-deal-name. That is accessing your API and returning data. What you probably are wanting is to expand on that and return the same data but in a different format like JSON or XML that can be consumed by something other then a browser. But yeah you already have an API you just need to expand on it.
A most basic example of an API function would be something like this (if you want to use JSON that is):
$return = BookManager::getAllBooks();
if(count($return) == 0){
$return = new stdClass();
$return->error = "no books found";
}
header('Content-type: application/json; charset=UTF-8');
echo(json_encode($return));
Where getAllBooks() returns an array with your books. A function that will probably allready exist in a finished site.
Hi There,
Ok, I need to create an API that a iPhone App Developer can communicate with… is this a simple process to do??