1.3 WADL示例
下面是一个雅虎新闻搜索应用的WADL描述示例。
- <?xml version="1.0"?>
- <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://research.sun.com/wadl/2006/10 wadl.xsd"
- xmlns:tns="urn:yahoo:yn" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- xmlns:yn="urn:yahoo:yn" xmlns:ya="urn:yahoo:api" xmlns="http://research.sun.com/wadl/2006/10">
- <grammars>
- <include href="NewsSearchResponse.xsd" />
- <include href="Error.xsd" />
- </grammars>
- <resources base="http://api.search.yahoo.com/NewsSearchService/V1/">
- <resource path="newsSearch">
- <method name="GET" id="search">
- <request>
- <param name="appid" type="xsd:string" style="query" required="true" />
- <param name="query" type="xsd:string" style="query" required="true" />
- <param name="type" style="query" default="all">
- <option value="all" />
- <option value="any" />
- <option value="phrase" />
- </param>
- <param name="results" style="query" type="xsd:int" default="10" />
- <param name="start" style="query" type="xsd:int" default="1" />
- <param name="sort" style="query" default="rank">
- <option value="rank" />
- <option value="date" />
- </param>
- <param name="language" style="query" type="xsd:string" />
- </request>
- <response>
- <representation mediaType="application/xml" element="yn:ResultSet" />
- <fault status="400" mediaType="application/xml" element="ya:Error" />
- </response>
- </method>
- </resource>
- </resources>
- </application>
第2—8行开始一个应用的描述,定义在应用描述的其他地方要用到的XML命名空间。
第2—9行定义了服务要用到的XML语法(grammars),这里包含了两个XMLSchema文件
的引用。
第16—45行描述了雅虎新闻搜索的Web资源和这个资源支持的HTTP方法。
第18—43行描述了 "search" GET方法,
第19—36行描述了 方法的输入,
第37—42行描述了 方法可能的输入,