你在这里


Drupal网站输出json数据供外部接口调用

James Qi 2016年12月19日 - 17:17 发布

  以前只从Drupal网站调用过外部的API数据,或者直接用Drupal的模块(例如DrupalGap)给外部提供json数据,我们自己对接口数据的了解不多,这段时间因为涉及到Drupal网站之间的数据调用、Drupal为外部提供通用的API接口、Drupal网站作为数据源来开发微信小程序等事情,让我们对API提供json数据了解更多,下面做一些笔记。

  可以使用的模块:

  各种访问网址:

  结构为:http://<your_domain>/<your_endpoint_path>/<your_resource_path>,其中

  • <your_domain>为网站域名
  • <your_endpoint_path>为创建的的endpoint名称
  • <your_resource_path>为资源名称(如果设置了alias则为设置的别名)

  例如:http://my.server.com/drupalgap/comment(默认返回xml格式,如果xml格式允许的话),要想试用json格式则为http://my.server.com/drupalgap/comment.json

  可用的资源名及操作办法:

  • comment
    • CRUD operations:
      • create: Create a comment
      • retrieve: Retrieve a comment
      • update: Update a comment
      • delete: Delete a comment
      • index: No description is available
    • Actions:
      • countAll: Return number of comments on a given node.
      • countNew: Returns number of new comments on a given node since a given timestamp.
  • contact
    • CRUD operations:
      • index: Get the contact categories.
    • Actions:
      • site: Submits the site-wide contact form.
      • personal: Submits a personal contact form.
  • drupalgap_content
    • Actions:
      • content_types_list: Gets a list of Drupal content types.
      • content_types_user_permissions: Returns a list of permissions the current user has for all content types.
  • drupalgap_system
    • Actions:
      • site_settings: Gets a list of various drupal settings and variables.
      • connect: The DrupalGap system connect with bundled result data.
  • drupalgap_taxonomy
    • Actions:
      • get_vocabularies: Returns a list of vocabularies.
      • get_terms: Returns a list of terms for a vocabulary.
  • drupalgap_user
    • Actions:
      • access: A service that performs a user_access function call for the current user.
      • login: The DrupalGap user login bundle resource.
      • logout: The DrupalGap user logout bundle resource.
      • register: The DrupalGap user register bundle resource.
      • roles_and_permissions: Retrieves a user's roles and permissions.
      • permissions: Retrieves the current user's permissions.
  • file
    • CRUD operations:
      • create: Create a file with base64 encoded data
      • retrieve: Retrieve a file
      • delete: Delete a file
      • index: List all files
    • Actions:
      • create_raw: Create a file with raw data.
  • flag
    • Actions:
      • is_flagged: Check if a entity was flagged by a user.
      • flag: Flags (or unflags) a entity.
      • countall: Count the flags number on a specific node.
  • node
    • CRUD operations:
      • create: Create a node
      • retrieve: Retrieve a node
      • update: Update a node
      • delete: Delete a node
      • index: List all nodes
    • Relationships:
      • files: This method returns files associated with a node.
      • comments: This method returns the number of new comments on a given node.
    • Targeted actions:
      • attach_file: Upload and attach file(s) to a node. POST multipart/form-data to node/123/attach_file
  • search_node
    • CRUD operations:
      • retrieve: No description is available
  • search_user
    • CRUD operations:
      • retrieve: No description is available
  • system
    • Actions:
      • connect: Returns the details of currently logged in user.
      • get_variable: Returns the value of a system variable using variable_get().
      • set_variable: Sets the value of a system variable using variable_set().
      • del_variable: Deletes a system variable using variable_del().
  • taxonomy_term
    • CRUD operations:
      • create: Create a term
      • retrieve: Retrieve a term
      • update: Update a term
      • delete: Delete the term
      • index: List all terms
    • Actions:
      • selectNodes: Returns all nodes with provided taxonomy id.
  • taxonomy_vocabulary
    • CRUD operations:
      • create: Create a taxonomy vocabulary
      • retrieve: Retrieve a taxonomy vocabulary
      • update: Update a taxonomy vocabulary
      • delete: Delete a taxonomy vocabulary
      • index: List all taxonomy vocabularies
    • Actions:
      • retrieveByMachineName: Returns a vocabulary based on machine name.
      • getTree: Returns a full list of taxonomy terms.
  • user
    • CRUD operations:
      • create: Create a user
      • retrieve: Retrieve a user
      • update: Update a user
      • delete: Delete a user
      • index: List all users
    • Actions:
      • login: Login a user for a new session
      • logout: Logout a user session
      • token: Returns the CSRF token.
      • request_new_password: Request a new password, given a user name or e-mail address
      • user_pass_reset: 
      • register: Register a user
    • Targeted actions:
      • cancel: Cancel a user
      • password_reset: No description is available
      • resend_welcome_email: No description is available

  http方法:

  • HTTP GET:"retrieve" and "index"
  • HTTP POST:"create"
  • HTTP PUT:"update" 
  • HTTP DELETE:"delete"

  关于CRUD、Actions、Targeted actions、Relationships的详细解释请看:Working with REST Server

  node页面操作例子:

  搜索:

  Views页面:可以自定义路径

自由标签:

评论

-- 发自IP地址: 61.183.172.43 (位置 | 谁是)

你好!谢谢关注,我们这几天自己也在查找这方面的资料用于微信小程序开发,找到后会及时更新的,我现在就来找、来更新。

James Qi / 祁劲松

添加新评论

Plain text

  • 不允许HTML标记。
  • 自动将网址与电子邮件地址转变为链接。
  • 自动断行和分段。
验证码
本问题用于测试您是否为人类访问者,避免自动垃圾发贴。
图形验证
键入显示在图片中的字符