Drupal 8 Web RESTFUL服务配置

By admin, 7 一月, 2017
  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>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
请输入"Drupal10"