Miscellaneous

  Home arrow Miscellaneous arrow Page 3 - Create Your Own Custom API
MISCELLANEOUS

Create Your Own Custom API
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 28
    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

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    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

    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 10 - Follow our Sitemap