第二十五章 源代码文件 REST API 参考(七)
Query
此方法对 IRIS
表执行 SQL
查询并返回结果。请求正文是指定查询的 JSON
对象。它返回一个匹配查询条件的对象数组。每个返回的对象都包含与查询返回的一行相关的信息。
URL
POST http://server:port/api/atelier/v1/namespace/action/query
SQL
查询在 URL
请求的正文中指定。查询必须在指定的命名空间中指定一个数据库。
此调用需要标头 Content-Type application/json。
JSON Messages
返回内容是一个对象数组。错误将出现在每个源代码文件对象的状态属性中:
{
"status": {
"errors": [],
"summary": ""
},
"console": [],
"result": {
"content": [
{
"ID": "%all",
"Description": "The Super-User Role"
},
{
"ID": "%db_%default",
"Description": "R/W access for this resource"
},
{
"ID": "%db_irislocaldata",
"Description": "R/W access for this resource"
},
...
{
"ID": "%sqltunetable",
"Description": "Role for use by tunetable to sample tables irrespective of row level security"
}
]
}
}
HTTP 返回码
HTTP 200
如果正常。- 如果传递的内容类型不是
application/json
,则HTTP 415
。 HTTP 500
如果发生意外错误(详细信息将在状态错误数组中)。
Search
此方法在 IRIS
数据库中查找具有指定内容的文件。 Search
方法在 API
的第 2
版中可用。此方法以旨在向用户显示的格式返回搜索结果。
URL
POST http://server:port/api/atelier/v2/namespace/action/search
URL Parameters
- 必需的
URL
参数?query=expression
指定要在指定文件中搜索的正则表达式或文本字符串。 - 必需的
URL
参数?files=file-list
提供以逗号分隔的文件或文件掩码列表,例如al*.mac
,以搜索指定的表达式。 - 可选的
URL
参数?regex=1
指定查询URL
参数包含正则表达式并且是默认值。?regexp=0
指定查询包含文本字符串,不应被解释为正则表达式。 - 可选的
URL
参数?sys=1
指定在搜索中包括系统文件。默认值为?sys=0
,不包括系统文件。 - 可选的
URL
参数?gen=1
指定在搜索中包含生成的文件。默认值为?gen=0
,它不包括生成的文件。 - 可选的
URL
参数?max=integer
指定要返回的最大结果数。默认值为?max=200
。
JSON Messages
以下搜索 REST
调用在所有 .cls
和 .mac
文件中搜索单词“Email”
,前面和后面都有一个空格。 (在正则表达式中,\s
由空格字符匹配。)
GET localhost:52773/api/atelier/v2/SAMPLES/action/search?query=.*\sEmail\s.*&files=*.cls,*.mac
此调用返回以下消息。返回消息可能因 SAMPLES
命名空间的内容而异。
{
"status": {
"errors": [],
"summary": ""
},
"console": [
"",
"Searching for '.*\\sEmail\\s.*' in '*.cls,*.mac'",
"Wasabi.Data.Employee.cls(Email): Property Email ",
"Wasabi.Person.API.Employee.cls(Email): Property Email ",
"ZAUTHENTICATE.mac(175): Properties(\"EmailAddress\") - Email address",
"Found 3 occurrence/s in 3 file/s."
],
"result": [
{
"doc": "Wasabi.Data.Employee.cls",
"matches": [
{
"member": "Email",
"text": "Property Email "
}
]
},
{
"doc": "Wasabi.Person.API.Employee.cls",
"matches": [
{
"member": "Email",
"text": "Property Email "
}
]
},
{
"doc": "ZAUTHENTICATE.mac",
"matches": [
{
"line": "175",
"text": "Properties(\"EmailAddress\") - Email address"
}
]
}
]
}
HTTP
返回码
- 如果请求有效,则为
HTTP 200
。 - 如果缺少必需的
URL
参数,则为HTTP 400
。