Web服务API

 
 

概观

Web服务API允许您将插件的功能(通常是外部函数)公开为Web服务。

一旦你完成了这个工作,你的插件的功能就可以被其他系统通过Web服务使用XML-RPC,REST或者SOAP之类的许多协议来访问。

作为Web服务函数公开函数是在一个名为services.php的文件中完成的。

services.php

  • 这个文件可以添加到你的插件数据库子文件夹。 (plugin/db/services.php)
  • 这个文件包含一个或两个数组。第一个数组声明您的Web服务功能。这些声明中的每一个都引用模块中的函数(通常是外部函数)。
$functions = array(
'local_PLUGINNAME_FUNCTIONNAME' => array( // local_PLUGINNAME_FUNCTIONNAME is the name of the web service function that the client will call.
'classname' => 'local_PLUGINNAME_external', // create this class in local/PLUGINNAME/externallib.php
'methodname' => 'FUNCTIONNAME', // implement this function into the above class
'classpath' => 'local/PLUGINNAME/externallib.php',
'description' => 'This documentation will be displayed in the generated API documentation
(Administration > Plugins > Webservices > API documentation)',
'type' => 'write', // the value is 'write' if your function does any database change, otherwise it is 'read'.
'ajax' => true, // true/false if you allow this web service function to be callable via ajax
'capabilities' => 'moodle/xxx:yyy, addon/xxx:yyy', // List the capabilities used in the function (missing capabilities are displayed for authorised users and also for manually created tokens in the web interface, this is just informative).
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) // Optional, only available for Moodle 3.1 onwards. List of built-in services (by shortname) where the function will be included. Services created manually via the Moodle interface are not supported.
)
);
  • 第二个可选数组声明了预建的服务。
// OPTIONAL
// During the plugin installation/upgrade, Moodle installs these services as pre-build services.
// A pre-build service is not editable by administrator.
$services = array(
'MY SERVICE' => array(
'functions' => array ('local_PLUGINNAME_FUNCTIONNAME'),
'restrictedusers' => 0, // if 1, the administrator must manually select which user can use this service.
// (Administration > Plugins > Web services > Manage services > Authorised users)
'enabled'=>1, // if 0, then token linked to this service won't work
)
);

每当services.php更改时,不要忘记在插件的version.php文件中增加版本号,否则Moodle将无法检测到更改。

详细的教程

这个系统的更详细的教程可以在下面的页面找到:

除此之外,该教程还介绍了如何定义函数的参数和返回值。

您将在Web服务模板插件中找到services.php文件的示例。这个插件包含一个web服务hello_world函数。

另外,为了使测试变得容易,插件与客户文件夹中的测试客户端一起分发。

Web服务API的更多相关文章

  1. C# 调用百度地图Web服务API

    最近公司项目中需要根据两个地点的交通路径和距离做一些数据推荐,为了程序的稳定和用户体验所以想从百度地图 API 采集数据保存到数据库中,经过一翻研究之后选定了百度地图 Web 服务 API 中的 Di ...

  2. Node.js调用百度地图Web服务API的Geocoding接口进行点位反地理信息编码

    (从我的新浪博客上搬来的,做了一些修改.) 最近迷上了node.js以及JavaScript.现在接到一个活,要解析一个出租车点位数据的地理信息.于是就想到使用Node.js调用百度地图API进行解析 ...

  3. C# 调用百度地图 Web 服务 API

    最近公司项目中需要根据两个地点的交通路径和距离做一些数据推荐,为了程序的稳定和用户体验所以想从百度地图 API 采集数据保存到数据库中,经过一翻研究之后选定了百度地图 Web 服务 API 中的 Di ...

  4. BMap:WEB 服务API

    ylbtech-Map-Baidu: WEB 服务API 百度地图Web服务API为开发者提供http/https接口,即开发者通过http/https形式发起检索请求,获取返回json或xml格式的 ...

  5. paper 88:人脸检测和识别的Web服务API

    本文汇总了全球范围内提供基于Web服务的人脸检测和识别的API,便于网络中快速部署和人脸相关的一些应用. 1:从How-old的火爆说起 最开始,网站的开发者只是给一个几百人的群发送email,请他们 ...

  6. C#封装百度Web服务API处理包含(Geocoding API,坐标转换API)

    1.创建基础参数类 public static class BaiduConstParams { public const string PlaceApIv2Search = "http:/ ...

  7. Rest风格WEB服务(Rest Style Web Service)的真相

    http://blog.csdn.net/jia20003/article/details/8365585 Rest风格WEB服务(Rest Style Web Service)的真相 分类: J2E ...

  8. Azure机器学习入门(四)模型发布为Web服务

    接Azure机器学习(三)创建Azure机器学习实验,下一步便是真正地将Azure机器学习的预测模型发布为Web服务.要启用Web服务发布任务,首先点击底端导航栏的运行即"Run" ...

  9. 使用Spring进行远程访问与Web服务

    1.1. 简介   Spring为各种远程访问技术的集成提供了整合类.Spring使得开发具有远程访问功能的服务变得相当容易,而这些远程访问服务由普通Spring POJO实现.目前,Spring支持 ...

随机推荐

  1. 洛谷P4707 重返现世 [DP,min-max容斥]

    传送门 前置知识 做这题前,您需要认识这个式子: \[ kthmax(S)=\sum_{\varnothing\neq T\subseteq S}{|T|-1\choose k-1} (-1)^{|T ...

  2. 一篇文章教你读懂UI绘制流程

    最近有好多人问我Android没信心去深造了,找不到好的工作,其实我以一个他们进行回复,发现他们主要是内心比较浮躁,要知道技术行业永远缺少的是高手.建议先阅读浅谈Android发展趋势分析,在工作中, ...

  3. Confluence 6 XML 备份失败的问题解决

    XML 站点备份仅仅被用于整合到一个新的数据库.设置一个测试服务器 或者 创建一个可用的备份策略 相对 XML 备份来说是更合适的策略. 相关页面: Enabling detailed SQL log ...

  4. 【linux】ssh无法root免密解决

    在设置了root的私钥和公钥,添加authorized_keys,修改文件权限为600后,用root账号 ssh localhost结果失败了,还是要密码. 解决: vim /etc/ssh/sshd ...

  5. HTML&javaSkcript&CSS&jQuery&ajax(二)

    一.HTML 1.标签<a href="http:www.baidu.com">This is a link </a>         <img sr ...

  6. Python 读写excel类

    #-*- coding: utf8 -*- import xlrd import xlwt from Public import GlobalClass def openexcel(path): tr ...

  7. 步步為營-96-MyMVC2

    說明:地址欄中的URL還存在一些不足之處 地址欄中最好能是http"www.sss.com/asdf/aaa 1.1 模擬路由的原理:創建Routing文件夾,并添加URLRoutingMo ...

  8. map reduce程序示例

    map reduce程序示例 package test2; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop. ...

  9. lsattr chattr 文件安全设置

    [root@test_android_client_download xianlaigames]# lsattr -------------e- ./jilinmj.apk[root@test_and ...

  10. 爬虫基础以及 re,BeatifulSoup,requests模块使用

    爬虫基础以及BeatifulSoup模块使用 爬虫的定义:向网站发起请求,获取资源后分析并提取有用数据的程序 爬虫的流程 发送请求 ---> request 获取响应内容 ---> res ...