Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,256
Total Threads: 81,169
Total Posts: 566,839
There are 43 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

API Development

Thread title: API Development
Reply  
Page 1 of 2 1 2 >
    Thread tools Search this thread Display Modes  
12-06-2011, 01:05 AM
#1
newkid is offline newkid
Status: Junior Member
Join date: Sep 2006
Location:
Expertise: PHP,MySQL, HTML(5), CSS
Software: Photoshop, Sublime Text2,MS VS
 
Posts: 63
iTrader: 1 / 100%
 

newkid is on a distinguished road

Send a message via Skype™ to newkid

  Old  API Development

Can anyone please explain in simple terms from a to z how to develop an API? Please do not assume developing an API with any other technology or programming language except PHP or pseudo-code. Thank you.

12-06-2011, 04:04 AM
#2
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,892
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

When asking for help on a forum it's an equal effort thing. You are never going to get more effort put into helping you than you put towards it. Go on Google and look up API development, if you don't understand the programming you'd have to learn that first anyways. If you need help with any specific questions we can help you with that, but no one is going to come in and write what you are asking for.

Reply With Quote
12-06-2011, 01:30 PM
#3
newkid is offline newkid
Status: Junior Member
Join date: Sep 2006
Location:
Expertise: PHP,MySQL, HTML(5), CSS
Software: Photoshop, Sublime Text2,MS VS
 
Posts: 63
iTrader: 1 / 100%
 

newkid is on a distinguished road

Send a message via Skype™ to newkid

  Old

I do know how to program. I have been searching the internet but the only tutorials I can find do not explain how they are developed. I never totally rely on forums.

Reply With Quote
12-06-2011, 06:14 PM
#4
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,892
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Thats more specific, but I'm afraid I don't really understand the question. All an API does is get requests (via GET/POST, SOAP, XML, REST, ect.) and send a response out via that method. What happens internally is no different than any other script.

Reply With Quote
12-07-2011, 04:11 AM
#5
newkid is offline newkid
Status: Junior Member
Join date: Sep 2006
Location:
Expertise: PHP,MySQL, HTML(5), CSS
Software: Photoshop, Sublime Text2,MS VS
 
Posts: 63
iTrader: 1 / 100%
 

newkid is on a distinguished road

Send a message via Skype™ to newkid

  Old

I understand this but I need to know how...something like a storyboard maybe. Basically if the same approach for learning control structures and OOP can be applied in order learn how to create an API would be great.

Reply With Quote
12-07-2011, 05:38 AM
#6
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,892
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Forgive me if I start a little basic here, Iíll get directly to your query soon.

The use for an API is to expose functionality without giving any sort of real access to your server. This allows third parties to do things while allowing you complete control over it. So to start developing an API you first need to figure out what functionality to expose. For the purposes of example letís look at this form the perspective of someone who needs to build an API. The reseller, RecordInformantô (completely made up), has a bunch of server that can search terabytes of information using a proprietary method they spent nearly a million dollars developing. Now we donít care what our clients sell this for or how do they any of that, they get to query us unlimited times per term for $50,000 a year. This business model presents an issue because it is unreasonable to give 5tb of information to each client with 10gb of data updates each day and expect them to have the server capabilities for this, furthermore you want to keep your search methods a secret. The solution to this is an API. We control all the servers and there is one copy of the data in our datacenter.

RecordInformant has a number of secret search features in PHP, two being searchAddressesForName($name) which can search though billions of address records in seconds and the second is searchFormerNames($name) which does about the same thing. To expose it they might use some code like the following (this is 100% untested PHP):
PHP Code:
<?php
include("../core/reallyImportantStuff.php");

//Check the cridentials
if(loginCheck($_REQUEST["user"],$_REQUEST["pass"])==true)
{
    
//A real script would use better methods to create XML but I don't want to look up the docs for how to do it.
    
    
$output '<?xml version="1.0"?>';
    if(
$_REQUEST["method"]=="getAddressesForName")
    {
        
$output .= "<response method='getAddressForName'>";
        
$addrs=getAddressesForName($_REQUEST["name"]);
        foreach(
$addrs as $addr)
        {
            
$output .= "<record><year>$year</year><fullAddress>$fullAddr</fulladdress></record>";
        }
        
$output .= "</response>";
    }
    elseif(
$_REQUEST["method"]=="searchFormerNames")
    {
        
$output .= "<response method='searchFormerNames'>";
        
$addrs=searchFormerNames($_REQUEST["name"]);
        foreach(
$addrs as $addr)
        {
            
$output .= "<record><year>$year</year><fullName>$fullName</fullName></record>";
        }
        
$output .= "</response>";
    }
}
else
{
    echo 
"No Acccess";
}
This API takes POST/GET requests and sends back an XML response. So a reseller would query the URL (https://api.recordinformant.com/api....Name&name=John Doe) and get the response:
HTML Code:
<?xml version="1.0"?>
<response method='getAddressForName'>
<record><year>1989</year><fullAddress>132 W. 54th Ave, New York, NY</fulladdress></record>
<record><year>1992</year><fullAddress>3524 E Grant St, Queens, NY</fulladdress></record>
<record><year>2002</year><fullAddress>4522 N Maple Ave, Portland, ME</fulladdress></record>
</response>
Which he can display to the client and maybe do some more things like integrate the addressed with Google maps.

APIs can get far more complicated than this, the one I work with the most (Ubersmith) has many functions that can do anything from create hosting accounts to generate invoices. Itís closed source so that is the way they chose to allow their clients to get custom stuff done. Different APIs also differ in their approach to this, some use GET/POST in and XML out, some use XML in and out, some use REST, SOAP or JSON both way. Furthermore it doesn't have to be in one file, instead of passing a method parameter some have a different file for each one (although almost all of them give a method in the response). Others that use a structured input such as XML can even support many queries at once, giving a structured response back.

12-07-2011, 06:15 PM
#7
newkid is offline newkid
Status: Junior Member
Join date: Sep 2006
Location:
Expertise: PHP,MySQL, HTML(5), CSS
Software: Photoshop, Sublime Text2,MS VS
 
Posts: 63
iTrader: 1 / 100%
 

newkid is on a distinguished road

Send a message via Skype™ to newkid

  Old

I don't bind you being basic about it. In fact, I loved your case study. Many thanks for the explanation and for not getting too complicated with the example. I have only one question. Is it a necessity to return the response with the name of the original request time?

Reply With Quote
12-07-2011, 06:42 PM
#8
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,892
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

I've never seen an API return the request time, if the issuing server wants to know it they can simply log it themselves.

Reply With Quote
12-07-2011, 06:44 PM
#9
newkid is offline newkid
Status: Junior Member
Join date: Sep 2006
Location:
Expertise: PHP,MySQL, HTML(5), CSS
Software: Photoshop, Sublime Text2,MS VS
 
Posts: 63
iTrader: 1 / 100%
 

newkid is on a distinguished road

Send a message via Skype™ to newkid

  Old

Sorry. I meant request name.

Reply With Quote
12-07-2011, 06:48 PM
#10
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,892
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

Not required but its nice to do. It's not really necessary in GET/POST inputs like that where only one request can be done at a time but if an API is going to be handling multiple requests at once it has to list what response belongs to what or it is useless.

Reply With Quote
Reply  
Page 1 of 2 1 2 >


Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed