Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Posts
    160
    Thanks
    10
    Thanked 1 Time in 1 Post

    Help with Product API

    Hi

    I want to learn how to build a XML API Server and have read up on Rest etc but really stuck where to even start and how the query would work.

    I have read a lot of stuff online and for simple API queries like sum to numbers I can find but nothing as complex as this using things like Count=3 and ShortDescription=Y.

    The bit I am most stuck on taking the URL and making that into the query. Actually getting the data out into the XML should not be so hard.

    I dont suppose anyone has done anything like this before and can share some code or examples or seen anything like this in a book or online.

    I want to make something like the following:-

    http://www.website.com/productxml?de...tDescription=Y

    Depending on what people request the output could be different and could contain any of the following:

    The following are acceptable field requests:

    BrandName
    Manufacturer
    ManufacturerPartNumber
    ModelNumber
    Name
    Origin
    Price
    Quality
    Stock
    ShortDescription
    SKU
    ThumbnailURL
    UPC
    Warranty
    ProductURL


    Many thanks in advance.
    Roy

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    PHP populates URL query strings inside the $_GET array. So, index.php?id=1 will have $_GET['id'] as '1' (note, all values will be string datatype) in index.php. So, the XML API you're making will accept GET queries, and return XML output based on those .
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #3
    Regular Coder
    Join Date
    Jan 2010
    Posts
    160
    Thanks
    10
    Thanked 1 Time in 1 Post
    Hi

    How would the query part work for example.

    Say I want a default of a maximum 100 results unless Count=250 etc and the customer Posts the following URL

    /productxml?dep=1&count=3&Name=Y&ShortDescription=Y

    How do you formulate the PHP and MySQL to accept Name=Y so it queries out the Name and if ShortDescription=Y how would this be coded in to pull out it in the results.

    Thanks
    Roy

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by ROYW1000 View Post
    Hi

    How would the query part work for example.

    Say I want a default of a maximum 100 results unless Count=250 etc and the customer Posts the following URL

    /productxml.php?dep=1&count=3&Name=Y&ShortDescription=Y

    How do you formulate the PHP and MySQL to accept Name=Y so it queries out the Name and if ShortDescription=Y how would this be coded in to pull out it in the results.

    Thanks
    Roy
    Just using your example, that would populate the $_GET array with:
    PHP Code:
    $_GET['dep'] = '1';
    $_GET['count'] = '3';
    $_GET['name'] = 'Y';
    $_GET['shortdescription'] = 'Y'
    All accessible inside productxml.php using $_GET['index']. If you're using them in mysql queries, remember to use mysql_real_escape_string() to stop SQL injection.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #5
    Regular Coder
    Join Date
    Jan 2010
    Posts
    160
    Thanks
    10
    Thanked 1 Time in 1 Post
    Hi

    How would I go about setting the default Count to say 100 unless the URL contains Count=1000 etc.

    Thanks
    Roy

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by ROYW1000 View Post
    Hi

    How would I go about setting the default Count to say 100 unless the URL contains Count=1000 etc.

    Thanks
    Roy
    You would check each one isset(), and if isset() returns false, you would produce and error or the default value.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •