doumi1884 2011-02-25 22:40
浏览 29

从REST API Server程序返回特定值到客户端 - PHP

I have an application which goes like this -

Host A asks Host B if a file exists in Host B or not. So, A requests a REST API call to B. Now B should send back reply (it can be thru status codes) to A, after checking for the which is sent as the argument thru URL from A to B.

I am new to the REST API concept. I am clear of how A sends request to B but, can anyone tell me how B returns the value to A.

Thanks

  • 写回答

2条回答 默认 最新

  • dongwu8064 2011-02-27 02:13
    关注

    There is nothing special about REST responses. They are regular HTTP responses. A REST service could respond with HTML page, XML or JSPN document, or a simple string value. Either way is valid.

    In your scenario, service A is a client to service B. A issues REST request (HTTP GET let's say),B accepts it and responds with putting a value in a response body (you choose the format), the A consumes the response body from B and does whatever it needs to do with it.

    This is a very rough example:

    A:

    <?php
    $response_from_b = file_get_contents('http://www.b.com/file/some-file-on-b.ext');
    // do whatever you need with $response_from_b
    ?>
    

    B:

    <?php
    $file_path = parse($_SERVER['REQUEST_URI']); // parse is your own function to get what you want form URI
    $native_response = file_exists($file_path); // your own function
    $response = decorate($native_response); // your own function
    echo $response;
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛