The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XML or JSON API?

Discussion in 'cPanel Developers' started by Azavia, May 20, 2010.

  1. Azavia

    Azavia Member

    Joined:
    Sep 23, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Pennsylvania
    Hi,

    I was just reading the API documentation. I have read that it is recommended to use JSON over XML because it is faster. Is this still the case, and why so? I don't see how one output format is faster than the other. If so, is the performance difference significant?

    I ask because I'm much more comfortable with using XML, but don't want a huge performance hit.
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi Azavia,

    I don't remember reading that, but would be interested to know where you found it in the API docs. Kinda curious now...

    If I had to venture a guess (concerning cPanel specifically), I'd say that it has to do with data manipulation on the server-side. When an API call is made the json-api or xml-api see the request, fetch info or perform action, then have to prepare the response. Preparing the response might take long for the xml-api binary.

    In general, I've heard is said that XML simply takes longer that JSON because the the character count, e.g. the amount of data. Also, I've heard it said that XML is slower than JSON when parsing in browser JS engines. It seems plausible with modern browsers (who are so intent on JS speed). But I've never seen, or search for, lab results.

    I wouldn't sweat it until you have proof which shows marked improvement. To my knowledge, WHM uses both xml-api and json-api (more json).
     
  3. Azavia

    Azavia Member

    Joined:
    Sep 23, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Pennsylvania
    Hi,

    Thanks for your reply. Here's where I found it: XML and JSON APIs

     
  4. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    This really depends on what you're doing.

    Currently JSON queries using API1 are broken, so if you're doing cpanel API w/ API1 calls, XML is probably the best option for the time being. (this will be fixed soon)

    That being said, the XML API w/ API1 can cause encoding issues due to the fact that the XMLAPI can return HTML output.

    If API1 isn't a concern for you, then the issue comes down to a matter of implementation.

    Within javascript, JSON is MUCH faster to use as it is the format used for datastructures with in JSON natively, there isn't much in terms of client side processing involved. While XML can put a bit more load on the server.

    In the context of a non-browser environment, I suggest using whatever you feel most comfortable with.
     
Loading...

Share This Page