Miscellaneous
  Home arrow Miscellaneous arrow Page 3 - Create Your Own Custom API
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MISCELLANEOUS

Create Your Own Custom API
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 10
    2005-02-02

    Table of Contents:
  • Create Your Own Custom API
  • Developing the basic API layout
  • The Client
  • The Server
  • The Server Class
  • The "Test" Step

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Create Your Own Custom API - The Client


    (Page 3 of 6 )

    Now we need to set up the client. Here, I've developed a cURL request (I used this because cURL is "big" and readily available and fairly simple to use). For testing purposes we are only going to have our static request XML message sent.

    <?php
    $request 
    "&lt;?xml version="1.0"?&gt;
    &lt;myXML&gt;
    &lt;function>order&lt;/function&gt;
    &lt;values&gt;
    &lt;orderID&gt;12345&lt;/orderID&gt;
    &lt;reference&gt;ref&lt;/reference&gt;
    &lt;/values&gt;
    &lt;/myXML&gt;
    "
    ;

    $url "http://www.mydomain.com/my_server.php";  
    // fake - obviosly!

    $ch curl_init();
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_POSTFIELDS$request); 
    // what to post
    curl_setopt($chCURLOPT_BINARYTRANSFER1); 
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_SSL_VERIFYHOST0);
    curl_setopt($chCURLOPT_SSL_VERIFYPEER0);
    $result curl_exec($ch);
    curl_close($ch);

    print 
    $result;
    ?>

    You will want to set the $url variable to the location of your server (that we are about to set up!). Other than that - the setup of the client application is simple!

    Also note the "curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);" line. Include this so the XML returned is returned as a string (so we can set the variable, parse the information, and use what was returned). Next - on to the server...

    More Miscellaneous Articles
    More By Codewalkers


       · The script is excellent..please change 2 things1) in the constructor please...
       · HI,I'm pretty new to this so perhaps I shouldn't be venturing into this at all...
     

    MISCELLANEOUS ARTICLES

    - Stopping CSRF Attacks in Your PHP Applicatio...
    - Quick and Dirty AJAX Tutorial
    - Flickr Puzzle Mashup
    - The PAVISE of Security
    - Creating a CAPTCHA with PHP
    - Sending SMS Thru HTTP
    - The Postal Fix - Part 2
    - Adding Mail with Exim
    - The Postal Fix - Part 1
    - Create Your Own Custom API
    - Adding Drop Shadows with PHP
    - Writing a Basic Authentication System in PHP
    - Overlapping Images with GD
    - Using Sockets in PHP
    - Dynamic CSS with PHP





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT