Drupal 8 Web RESTFUL服务配置

admin 提交于 星期六, 01/07/2017 - 10:03
  1. 先安装一个RESTUI模块
  2. 启用配置好之后可以访问GET接口,例如:http://cto.eguidedog.net/node/241?_format=json
  3. POST接口,例如:curl -H "Content-Type: application/json" -X POST -d '{"type":[{"target_id":"braille_printing_application"}],"title":[{"value":"test2"}],"field_address":[{"value":"addr2"}],"field_name":[{"value":"name2"}],"field_phone":[{"value":"phone2"}],"field_zipcode":[{"value":"zipcode2"}]}' http://cto.eguidedog.net/entity/node

  4. 更多信息参考:https://www.drupal.org/docs/8/core/modules/rest/javascript-and-drupal-8-restful-web-services
  5. 关于上传文件,可以参考:https://www.drupal.org/node/1927648 ,https://www.drupal.org/node/2748013 ,http://drupal.stackexchange.com/questions/118106/how-to-send-files-to-drupal-8-via-rest。更容易的方法是通过PHP上传,然后引用URL。PHP上传脚本很简单:

<?php
$uploadfile = 'images/' . basename($_FILES['file']['name']) . '.jpg';
move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile);
echo 'http://eguidedog.net/GodErlang/images/' . $uploadfile . '.jpg';
?>

标签

添加新评论

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • Web page addresses and email addresses turn into links automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
请输入"Drupal8"