writecrow/rest_feedback_endpoint

接收 POST 请求的 REST 端点

1.1.0 2023-07-09 01:32 UTC

This package is auto-updated.

Last update: 2024-09-09 04:04:57 UTC


README

本模块提供接收 POST 请求的 REST 资源端点,并发送包含内容的电子邮件。本模块中的示例演示了反馈表单内容,但 SubmitIssue 端点可以作为其他类型端点的模型。

推荐配置

  1. 使用 simple_oauth 模块
  2. 启用 Drupal 核心的 rest_ui 模块。
  3. 转到 /admin/config/services/rest 并启用 "提交问题" 端点
    • 粒度:资源
    • 方法:POST
    • 接受的请求格式:json, xml
    • 身份验证提供者:oauth2
  4. /admin/people/permissions#module-rest 设置权限,以确定哪些角色可以访问端点
  5. 确保配置 services.yml 文件,以便端点可以被访问
cors.config:
  enabled: true
  # Specify allowed headers, like 'x-allowed-header'.
  allowedHeaders: ['x-csrf-token','authorization','content-type','accept','origin','x-requested-with', 'access-control-allow-origin','x-allowed-header']
  # Specify allowed request methods, specify ['*'] to allow all possible ones.
  allowedMethods: ['GET', 'POST']
  # Configure requests allowed from specific origins (ideally, limit this to the expected origins)
  allowedOrigins: ['*']
  # Sets the Access-Control-Expose-Headers header.
  exposedHeaders: false
  # Sets the Access-Control-Max-Age header.
  maxAge: false
  # Sets the Access-Control-Allow-Credentials header.
  supportsCredentials: false

如果复制原始演示 SubmitIssue,请特别注意注解,它定义了路由,并且必须遵循特定的格式才能与 POST 请求一起工作(见https://www.drupal.org/forum/support/post-installation/2017-02-21/post-return-no-route-found-error-while-get-request-is

 * @RestResource(
 *   id = "feedback_endpoint_bug_report",
 *   label = @Translation("Submit an issue"),
 *   uri_paths = {
 *    "canonical" = "/submit-issue",
 *    "create" = "/submit-issue"
 *   }
 * )