<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jojo's blog--快樂憂傷都與你同在
    為夢想而來,為自由而生。 性情若水,風起水興,風息水止,故時而激蕩,時又清平……
    posts - 11,  comments - 30,  trackbacks - 0
    Long weekends reduce brain cells to jelly.  Worked on a few things over the weekend, nothing really to report except write down this simple example.

    The next book has far too many XML chapters in it, or at least it seems that way at the moment.  I had a good anti-WS-bloat rant in Amsterdam recently.  In a nutshell: most of the web services stack is bloatware that doesn't get used for most applications.  90% of the time you can get away with knowing no SOAP, WSDL, or any of that stuff.  You can just use REST - Representational State Transfer.  This is basically an HTTP GET request with parameters, and in return you get an XML document, in other words XML over HTTP.   It works very nicely and is simple.  I was trying to explain this to somebody here at work, so I wrote a very basic REST server/client pair in PHP in five minutes to demonstrate.  Here's the code, which is doubled in size due to comments.

    REST server for imaginary stock price lookup

    restserver.php


     1 <?php
     2 
     3   // check which stock we want to look up
     4   $stock = $_GET['stock'];
     5 
     6   // look up the stock
     7   $price = lookup($stock);
     8 
     9   // format stock quote as XML
    10   $string = "<stockquote><stockprice>$price</stockprice></stockquote>";
    11 
    12   // make it into a proper XML document with header etc
    13   $xml = simplexml_load_string($string);
    14 
    15   // send an XML mime header
    16   header("Content-type: text/xml");
    17 
    18   // output correctly formatted XML
    19   echo $xml->asXML();
    20 
    21 // that's the end of the main code, function below is just a stub
    22 
    23   function lookup($s)
    24   {
    25     // all stocks are worth $1 for this basic example
    26     // but you would look it up in a database if you had one
    27     return 1;
    28   }
    29 

    REST client demo

    restclient.php


     1 <?php
     2 
     3 // query the REST server and load the returned XML as a PHP object
     4 // note parameters go to REST server as HTTP GET parameters
     5 $stock='MSFT';
     6 
     7 $xml = simplexml_load_file("http://localhost/demo/restserver.php?stock=$stock");
     8 
     9 echo "$stock stock price today is ";
    10 echo $xml->stockprice;
    11 
    12 ?>
    13 
    14 

    Basically you don't need to know anything about Web Services or even XML to make and consume REST Web Services.   This assertion greatly irritates a lot of people.

    I'm not saying there isn't a need for SOAP and WS-*, just that often simple tools will do the job.  It's just another version of the 80% rule.  This seems to be a theme in my personal consumption of technology.


    posted on 2008-10-07 21:16 Blog of JoJo 閱讀(1335) 評論(0)  編輯  收藏 所屬分類: Linux 技術相關

    <2025年7月>
    293012345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲成av人片天堂网无码】| 久久久久免费视频| 伊人久久综在合线亚洲2019| 国产乱弄免费视频| 无码乱肉视频免费大全合集| 成人爽a毛片免费| 无人视频免费观看免费视频| 亚洲youjizz| 久久综合亚洲色一区二区三区| 久久久久亚洲爆乳少妇无| 最近免费中文字幕大全| 131美女爱做免费毛片| 成在人线av无码免费高潮喷水| 免费国产高清毛不卡片基地| 最新亚洲春色Av无码专区| 亚洲精品电影在线| 亚洲国产精品无码久久久不卡| 免费一级毛片一级毛片aa| 午夜一区二区免费视频| 免费无码又黄又爽又刺激| 中国人xxxxx69免费视频| 四虎国产成人永久精品免费| 大地资源中文在线观看免费版| 久青草视频在线观看免费| 九九免费精品视频在这里| 日本高清不卡中文字幕免费| 看一级毛片免费观看视频| 亚洲AV无码一区二区三区电影| 亚洲色偷偷偷综合网| 亚洲色无码国产精品网站可下载| 亚洲无吗在线视频| 日韩亚洲产在线观看| 亚洲一卡2卡3卡4卡乱码 在线| 亚洲视频无码高清在线| 亚洲国产精品免费观看| 亚洲欧美日韩中文字幕一区二区三区 | 国产精品无码素人福利免费| 免费a级毛片无码a∨蜜芽试看| 免费毛片a在线观看67194| 久久成人a毛片免费观看网站| 亚洲人成色4444在线观看|