<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 閱讀(1331) 評論(0)  編輯  收藏 所屬分類: Linux 技術相關

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲精品无码专区在线| 亚洲视频一区二区三区四区| 日韩在线视频线视频免费网站| 成人a免费α片在线视频网站 | 亚洲黄色片免费看| 亚洲精品高清视频| 99久久精品免费视频| 久久亚洲国产精品成人AV秋霞| 午夜视频在线免费观看| 亚洲色图视频在线观看| 37pao成人国产永久免费视频| 亚洲美女激情视频| A在线观看免费网站大全| 亚洲性线免费观看视频成熟| 四虎成人免费观看在线网址| 婷婷亚洲综合一区二区| 亚洲人成无码网WWW| 成人爽a毛片免费| 亚洲成A∨人片在线观看无码| 免费阿v网站在线观看g| 国产精品亚洲AV三区| 亚洲精品人成无码中文毛片| 免费无码又爽又刺激网站直播 | 免费在线观看亚洲| 亚洲色欲色欲www在线丝| 久久久精品2019免费观看| 亚洲精品伊人久久久久| 可以免费观看一级毛片黄a| 91免费在线视频| 亚洲欧洲另类春色校园小说| 日韩激情无码免费毛片| 国产免费牲交视频免费播放 | 久久水蜜桃亚洲AV无码精品| 亚洲情a成黄在线观看| 4399影视免费观看高清直播| 韩国亚洲伊人久久综合影院| 日韩va亚洲va欧洲va国产| 成在人线AV无码免费| 两个人看的www高清免费观看| 亚洲喷奶水中文字幕电影| 亚洲 综合 国产 欧洲 丝袜|