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. oracle user locked(timed)处理

    故障现象: SQL> connect scott/scottERROR:ORA-01017: invalid username/password; logon deniedSQL> con ...

  2. input,select默认颜色修改

    input::-webkit-input-placeholder{color: #7f7f7f;} select{color: #7f7f7f} option{color: #7f7f7f;}

  3. mabatis的批量新增sql 初级的 初级的 初级的

    简单描述:做开发的时候,会遇到一次插入好多条记录,怎么做好呢? 解决思路:循环insert啊!  哪凉快那呆着去←!←  这样会增加数据库开销的,当然不能这么干了,要在sql上下功夫.看代码,一下就明 ...

  4. 使用 declare 语句和strict_types 声明来启用严格模式:

    使用 declare 语句和strict_types 声明来启用严格模式: Caution: 启用严格模式同时也会影响返回值类型声明. Note: 严格类型适用于在启用严格模式的文件内的函数调用,而不 ...

  5. 解决linux下svn update 产生Node remains in conflict的问题

    提交一个文件 服务器上死活更新不了 是因为有冲突,解决办法:svn revert --depth=infinity /var/SvnProject/APITest 再次执行更新 进有改动的文件夹,更新 ...

  6. C语言实现split以某个字符分割一个字符串

    方式一: 使用strtok # include <string.h> # include <stdio.h> void split(char *src,const char * ...

  7. 20165206第4次实验《Android程序设计》实验报告

    20165206第4次实验<Android程序设计>实验报告 一.实验报告封面 课程:Java程序设计 班级:1652班 姓名:韩啸 学号:20165206 指导教师:娄嘉鹏 实验日期:2 ...

  8. python 0007

    #coding='utf-8'# import re import os def get_list(): list_file=[] for f in os.listdir(): if f.endswi ...

  9. 金蝶k3完全卸载,注册表手动清理

    HKEY_LOCAL_MACHINE\SOFTWARE\KINGDEE 如果操作系统是64位的,在注册表目录:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node下面还有一个 ...

  10. asp.net core ioc 依赖注入

    1.生命周期 内置的IOC有三种生命周期: Transient: Transient服务在每次被请求时都会被创建.这种生命周期比较适用于轻量级的无状态服务. Scoped: Scoped生命周期的服务 ...