简介 - 什么是REST ++?

TigerGraph TM 系统使用着名的REpresentational State Transfer(REST)架构来管理与TigerGraph核心组件,图形处理引擎(GPE)和图形存储引擎(GSE)的通信。REST ++(或RESTPP)是TigerGraph定制的REST服务器。(请参见下面的图1)当上层组件(如Platform Web UI或GSQL)希望访问图形引擎时,它会向REST ++服务器发送请求。用户还可以通过使用系统附带的标准REST API之一,或通过创作然后使用自定义终端API,直接与REST ++服务器通信。本文档描述了内置端点的API,该API提供了对图形数据进行基本查询和操作的方法。

图1 :TigerGraph系统框图

像大多数RESTful系统一样,REST ++采用HTTP协议(特别是没有请求流水线的HTTP / 1.1)。因此,REST API具有请求方法和URL,响应状态代码和数据响应。本指南介绍了用于查询,更新和从图数据中删除的请求方法和URL。它还描述了数据响应的格式。

TigerGraph REST API使用三种HTTP请求方法:

  • GET 用于请求数据。

  • POST 用于发送数据。

  • DELETE 用于删除数据。

如果用户提交不支持的HTTP方法,API将返回一条错误消息:“未找到端点”。

REST Request Format

curl -X method "http://server_ip:9000/path_to_endpoint?request_parameters"
Example:
Example: Get all User vertices

curl -X GET "http://172.16.0.222:9000/graph/vertices/User"

 

To list only the first three vertices, we can set limit = 3:

 

Example: Get up to 3 User vertices
curl -X GET "http://localhost:9000/graph/socialNet/vertices/User?limit=3"

 

Input Data for POST

 

Input data for POST requests should be in JSON format. There are two ways to supply the data: inline or in a separate file.

 

Inline Data

 

The data should be formatted as a single string without linebreaks. Use the curl - option, followed by the JSON string.

 

Syntax for a POST request with Inline Data Payload
curl -X POST -d 'json_string' "http://server_ip:9000/path_to_endpoint?request_parameters"

 

The following example uses the POST /graph endpoint to insert one User type vertex whose id value is "id6" into the graph called "socialNet".

 

Example using inline input data
curl -X POST -d '{"vertices":{"User":{"id6":{"id":{"value":"id6"}}}}}' "http://172.16.0.222:9000/graph"

 

Data File

 

Often it will be more convenient for the input data to be in a separate file, especially if it is large.

 

Use the curl option --data-binary @path_to_file as in the example below:

 

Syntax for a POST request with Payload Data File
curl -X POST --data-binary @json_file "http://server_ip:9000/path_to_endpoint?request_parameters"

 

If we now store the data string in a file (say, my_input.json), then the example above becomes the following:

 

Example using inline input data
curl -X POST --data-binary @my_input.json "http://172.16.0.222:9000/graph"

 

REST++ Output 

To make the output more human readable, use the jq command or Python json library built into most Linux installations. Specifically,

curl -X method "http://server_ip:9000/path_to_endpoint?request_parameters" | jq .
curl -X method "http://server_ip:9000/path_to_endpoint?request_parameters" | python -m json.tool

Example:

curl -X GET "http://172.16.0.222:9000/graph/vertices/User?limit=3"

without postprocess formatting returns the following:

{"version":{"api":"v2","schema":0},"error":false,"message":"","results":[{"v_id":"id2","v_type":"User","attributes":{}},{"v_id":"id14","v_type":"User","attributes":{}},{"v_id":"id58","v_type":"User","attributes":{}}]}

 

On the other hand,

curl -X GET "http://172.16.0.222:9000/graph/vertices/User?limit=3" | jq .

returns this much more readable output:

{

  "version": {

    "api": "v2",

    "schema": 0

  },

  "error": false,

  "message": "",

  "results": [

    {

      "v_id": "id2",

      "v_type": "User",

      "attributes": {}

    },

    {

      "v_id": "id14",

      "v_type": "User",

      "attributes": {}

    },

    {

      "v_id": "id58",

      "v_type": "User",

      "attributes": {}

    }

  ]

}

GET /echo and POST /echo

These endpoints are simple diagnostic utilities which respond with the following message.

GET echo/ Request and Response
curl -X GET "http://localhost:9000/echo" { "error": false, "message": "Hello GSQL" }

POST /echo has the same response as GET /echo.

GET /endpoints

This endpoint returns a list of the installed endpoints and their parameters. There are three types of endpoints, described in the table below.

Type

Description

builtin

preinstalled in the TigerGraph system

dynamic

generated when compiling GSQL queries

static

user-installed endpoints

 

 

GET /graph/graph_name/vertices

Syntax for GET /graph/vertices
curl -X GET "http://server_ip:9000/graph/graph_name/vertices/{vertex_type}[/{vertex_id}/]

This endpoint returns all vertices having the type vertex_type in the graph called graph_name . Optionally, the user can instead chose a particular vertex by including its primary_id at the vertex_id field For example:

 graph_name: 图分组名称

 vertex_type: 点的类型名称。目前demo:User Page Product DescWord NameUser VidUser Video AttributeTag Person SocialUser

 vertex_id: 点的ID类型

curl -X GET "http://172.16.0.222:9000/graph/vertices/User/id1" | jq .

{ "version": { "api": "v2", "schema": 0 }, "error": false, "message": "", "results": [ { "v_id": "id1", "v_type": "User", "attributes": {} } ] }

 count_only:  BOOL(1/0/true/false)

curl -X GET 'http://172.16.0.222:9000/graph/vertices/SocialUser?count_only=1' | jq .

{

  "version": {

    "api": "v2",

    "schema": 0

  },

  "error": false,

  "message": "",

  "results": [

    {

      "v_type": "SocialUser",

      "count": 10

    }

  ]

}

 

 filter: 过滤attributes的属性 

curl -X GET 'http://172.16.0.222:9000/graph/vertices/SocialUser?filter=name="peter"' | jq .

{

  "version": {

    "api": "v2",

    "schema": 0

  },

  "error": false,

  "message": "",

  "results": [

    {

      "v_id": "6",

      "v_type": "SocialUser",

      "attributes": {

        "name": "peter",

        "isActive": true,

        "registration_timestamp": 146000000

      }

    }

  ]

}

  limit:限制放回个数

curl -X GET 'http://172.16.0.222:9000/graph/vertices/SocialUser?limit=2' | jq .

{

  "version": {

    "api": "v2",

    "schema": 0

  },

  "error": false,

  "message": "",

  "results": [

    {

      "v_id": "6",

      "v_type": "SocialUser",

      "attributes": {

        "name": "peter",

        "isActive": true,

        "registration_timestamp": 146000000

      }

    },

    {

      "v_id": "5",

      "v_type": "SocialUser",

      "attributes": {

        "name": "steven",

        "isActive": false,

        "registration_timestamp": 145000000

      }

    }

  ]

}

   select: 返回筛选的attributes的属性

curl -X GET 'http://172.16.0.222:9000/graph/vertices/SocialUser?select=name' | jq .

{

 

  "version": {

 

    "api": "v2",

 

    "schema": 0

 

  },

 

  "error": false,

 

  "message": "",

 

  "results": [

 

    {

 

      "v_id": "6",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "peter"

 

      }

 

    },

 

    {

 

      "v_id": "5",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "steven"

 

      }

 

    },

 

    {

 

      "v_id": "8",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "joseph"

 

      }

 

    },

 

    {

 

      "v_id": "7",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "james"

 

      }

 

    },

 

    {

 

      "v_id": "2",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "matthew"

 

      }

 

    },

 

    {

 

      "v_id": "4",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "paul"

 

      }

 

    },

 

    {

 

      "v_id": "9",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "thomas"

 

      }

 

    },

 

    {

 

      "v_id": "1",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "john"

 

      }

 

    },

 

    {

 

      "v_id": "0",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "luke"

 

      }

 

    },

 

    {

 

      "v_id": "3",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "mark"

 

      }

 

    }

 

  ]

 

}

    sort: 通过筛选的attributes的属性进行排序

curl -X GET 'http://172.16.0.222:9000/graph/vertices/SocialUser?sort=name' | jq .

{

 

  "version": {

 

    "api": "v2",

 

    "schema": 0

 

  },

 

  "error": false,

 

  "message": "",

 

  "results": [

 

    {

 

      "v_id": "7",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "james",

 

        "isActive": true,

 

        "registration_timestamp": 147000000

 

      }

 

    },

 

    {

 

      "v_id": "1",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "john",

 

        "isActive": true,

 

        "registration_timestamp": 1410000000

 

      }

 

    },

 

    {

 

      "v_id": "8",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "joseph",

 

        "isActive": true,

 

        "registration_timestamp": 148000000

 

      }

 

    },

 

    {

 

      "v_id": "0",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "luke",

 

        "isActive": true,

 

        "registration_timestamp": 1400000000

 

      }

 

    },

 

    {

 

      "v_id": "3",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "mark",

 

        "isActive": true,

 

        "registration_timestamp": 143000000

 

      }

 

    },

 

    {

 

      "v_id": "2",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "matthew",

 

        "isActive": false,

 

        "registration_timestamp": 1420000000

 

      }

 

    },

 

    {

 

      "v_id": "4",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "paul",

 

        "isActive": true,

 

        "registration_timestamp": 144000000

 

      }

 

    },

 

    {

 

      "v_id": "6",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "peter",

 

        "isActive": true,

 

        "registration_timestamp": 146000000

 

      }

 

    },

 

    {

 

      "v_id": "5",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "steven",

 

        "isActive": false,

 

        "registration_timestamp": 145000000

 

      }

 

    },

 

    {

 

      "v_id": "9",

 

      "v_type": "SocialUser",

 

      "attributes": {

 

        "name": "thomas",

 

        "isActive": true,

 

        "registration_timestamp": 149000000

 

      }

 

    }

 

  ]

 

}

 

GET /graph/graph_name/edges

Syntax for GET /graph/edges
curl -X GET "http://localhost:9000/graph/graph_name/edges/{source_vertex_type}/{source_vertex_id}/[{edge_type}/[{target_vertex_type}/[{target_vertex_id}]]]

This endpoint returns all edges which connect to a given vertex ID in the graph called graph_name . A source vertex ID must be given. The user may optionally specify the edge type, the target vertex type, and the target vertex ID. The URL format is as follows:

  • edge_type - type name of the edges. Use "_" to permit any edge type. Omitting the edge_type field from the URL also permits any edge type. However, skipping edge_type also means that target_vertex_type and target_vertex_id must be skipped.
  • target_vertex_type type name of the target vertices.
  • target_vertex_id ID of the target vertex.

   source_vertex_type: 源点,如VidUser

   source_vertex_id: 源点ID,如 0

   edge_type: 边的类型,如User_Video

  target_vertex_type: 目标点,如 User

  target_vertex_id: 目标点ID ,如Video

     sort: 通过筛选的attributes的属性进行排序

curl -X GET 'http://172.16.0.222:9000/graph/edges/VidUser/0/User_Video/Video' | jq .

{

 

  "version": {

 

    "api": "v2",

 

    "schema": 0

 

  },

 

  "error": false,

 

  "message": "",

 

  "results": [

 

    {

 

      "e_type": "User_Video",

 

      "directed": false,

 

      "from_id": "0",

 

      "from_type": "VidUser",

 

      "to_id": "2",

 

      "to_type": "Video",

 

      "attributes": {

 

        "rating": 5.2,

 

        "date_time": 0

 

      }

 

    },

 

    {

 

      "e_type": "User_Video",

 

      "directed": false,

 

      "from_id": "0",

 

      "from_type": "VidUser",

 

      "to_id": "0",

 

      "to_type": "Video",

 

      "attributes": {

 

        "rating": 6.8,

 

        "date_time": 0

 

      }

 

    },

 

    {

 

      "e_type": "User_Video",

 

      "directed": false,

 

      "from_id": "0",

 

      "from_type": "VidUser",

 

      "to_id": "3",

 

      "to_type": "Video",

 

      "attributes": {

 

        "rating": 10,

 

        "date_time": 0

 

      }

 

    }

 

  ]

 

}

 count_only、limit、select、sort、timeout 跟/graph/vertices一样

 

/graph/graph_name/edges has two optional parameters "count_only" and "not_wildcard":

  • count_only: If it is true, the results contains only the number of edges selected. The default value is false.
  • not_wildcard: This determines how the edge type name "_" is interpreted. If false (which is the default), "_" means all edge types are included. If not_wildcard is true, "_" is interpreted literally to select only edges with edge type name equal to underscore.

DELETE /graph/vertices

curl -X DELETE "http://server_ip:9000/graph/graph_name/vertices/{vertex_type}[/{vertex_id}/]

 graph_name: 图分组名称

 vertex_type: 点的类型名称。目前demo:User Page Product DescWord NameUser VidUser Video AttributeTag Person SocialUser

 vertex_id: 点的ID类型

This endpoint deletes the given vertex(vertices) in the graph called graph_name . The URL is exactly the same as GET /graph/graph_name/vertices. This endpoint has an additional parameter "permanent", whose default value is false. If "permanent" is true, the deleted vertex ids can never be inserted back, unless the graph is dropped or the graph store is cleared.

Example:

curl -X DELETE "http://172.16.0.222:9000/graph/vertices/User/id64" | jq .

 

{

 

  "version": {

 

    "api": "v2",

 

    "schema": 0

 

  },

 

  "error": false,

 

  "message": "",

 

  "results": {

 

    "v_type": "User",

 

    "deleted_vertices": 1

 

  }

 

}

DELETE /graph/edges

curl -X DELETE "http://server_ip:9000/graph/graph_name/edges/{source_vertex_type}/{source_vertex_id}/[{edge_type}/[{target_vertex_type}/[{target_vertex_id}]]]

  source_vertex_type: 源点,如VidUser

   source_vertex_id: 源点ID,如 0

   edge_type: 边的类型,如User_Video

  target_vertex_type: 目标点,如 User

  target_vertex_id: 目标点ID ,如Video

   sort: 通过筛选的attributes的属性进行排序

Example:

curl -X DELETE "http://172.16.0.222:9000/graph/edges/VidUser/0/User_Video/Video" | jq .

 

{

 

  "version": {

 

    "api": "v2",

 

    "schema": 0

 

  },

 

  "error": false,

 

  "message": "",

 

  "results": [

 

    {

 

      "e_type": "User_Video",

 

      "deleted_edges": 3

 

    }

 

  ]

 

}

 

This endpoint deletes the given edge(s). The URL is exactly the same as GET /graph/edges.

Advanced Parameters for /graph/vertices and /graph/edges

The above four endpoints, GET /graph/graph_name/vertices, GET /graph/graph_name/edges, DELETE /graph/graph_name/vertices, and DELETE /graph/graph_name/edges, have optional URL parameters for further operations:

  1. Select: Specify which attributes to be returned (GET only).
  2. Filter: Apply a filter on the vertices or edges, based on their attribute values.
  3. Limit: Limit the total number of vertices or edges.
  4. Sort: Sort the data. (For DELETE, sort should be used with limit together.)
  5. Timeout: Timeout in seconds. If set to 0, use system wide endpoint timeout setting.

The parameter 'Limit' can reduce the search space and leads to quick response of queries. However if Limit and Sort are both provided, the query still needs to traverse all potential vertices/edges and it might lead to slow query response on large graph.

Select

By default the GET /graph/vertices and /graph/edges endpoints return all the attributes of the selected vertices or edges. The select parameter can be used to specify either the desired or the undesired attributes. The format is select=attribute_list, where attribute_list is a list of comma-separated attributes. Listing an attribute name means that this attribute should be included, while an attribute name preceded by a minus sign means that this attribute should be excluded. An underscore means all attributes.

It is illegal to specify both desired and undesired attributes in the same request.

Example Query: Return the date_time attribute of all product vertices on socialNet.

curl -X GET "http://172.16.0.222:9000/graph/vertices/Product?select=date_time"

Filter

The filter parameter is a set of conditions analogous to the WHERE clause in industry-standard SQL language. The format is filter=filter_list, where filter_list is a list of comma-separated filters, and each filter is the concatenation of an attribute, an operator, and a value (with no white spaces separating the parts). The following six comparison operators are supported:

  1. equal to

  2. != not equal to

  3. greater than

  4. >= greater than or equal to

  5. less than

  6. <= less than or equal to

Here is an example request: It returns all User vertices with age greater than or equal to 30.

curl -X GET "http://172.16.0.222:9000/graph/vertices/User?filter=age>=30" 

 

 

 

 

 

{"version":{"api":"v2","schema":0},"error":false,"message":"","results":[{"v_id":"id2","v_type":"User","attributes":{}},{"v_id":"id14","v_type":"User","attributes":{}},{"v_id":"id58","v_type":"User","attributes":{}}]}

TigerGraph REST++API的更多相关文章

  1. 干货来袭-整套完整安全的API接口解决方案

    在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...

  2. 12306官方火车票Api接口

    2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...

  3. 几个有趣的WEB设备API(二)

    浏览器和设备之间还有很多有趣的接口, 1.屏幕朝向接口 浏览器有两种方法来监听屏幕朝向,看是横屏还是竖屏. (1)使用css媒体查询的方法 /* 竖屏 */ @media screen and (or ...

  4. html5 canvas常用api总结(三)--图像变换API

    canvas的图像变换api,可以帮助我们更加方便的绘画出一些酷炫的效果,也可以用来制作动画.接下来将总结一下canvas的变换方法,文末有一个例子来更加深刻的了解和利用这几个api. 1.画布旋转a ...

  5. JavaScript 对数据处理的5个API

    JavaScript对数据处理包括向上取整.向下取整.四舍五入.固定精度和固定长度5种方式,分别对应ceil,floor,round,toFixed,toPrecision等5个API,本文将对这5个 ...

  6. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  7. javascript的api设计原则

    前言 本篇博文来自一次公司内部的前端分享,从多个方面讨论了在设计接口时遵循的原则,总共包含了七个大块.系卤煮自己总结的一些经验和教训.本篇博文同时也参考了其他一些文章,相关地址会在后面贴出来.很难做到 ...

  8. 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino

    大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...

  9. 在一个空ASP.NET Web项目上创建一个ASP.NET Web API 2.0应用

    由于ASP.NET Web API具有与ASP.NET MVC类似的编程方式,再加上目前市面上专门介绍ASP.NET Web API 的书籍少之又少(我们看到的相关内容往往是某本介绍ASP.NET M ...

随机推荐

  1. ping 和 远程桌面 与防火墙的关系

    现象: 初始化服务器时,人们为了方便,常常关闭防火墙,这样做很危险.我们经常遇到问题是,防火墙一旦打开,ping和远程桌面就会有问题. 有时ping不通,但能远程:但有时ping通,又远程不了:有时都 ...

  2. iOS多线程全套:线程生命周期,多线程的四种解决方案,线程安全问题,GCD的使用,NSOperation的使用

    目的 本文主要是分享iOS多线程的相关内容,为了更系统的讲解,将分为以下7个方面来展开描述. 多线程的基本概念 线程的状态与生命周期 多线程的四种解决方案:pthread,NSThread,GCD,N ...

  3. 一步一步学Silverlight 2系列(18):综合实例之RSS阅读器

    一步一步学Silverlight 2系列(18):综合实例之RSS阅读器   概述 Silverlight 2 Beta 1版本发布了,无论从Runtime还是Tools都给我们带来了很多的惊喜,如支 ...

  4. WAS:Thread "server.startup : 1" (00000020) and may be hung异常

    有现场server启动时,启动不了,后台报错如下: [// ::: CST] ThreadMonitor W WSVR0605W: Thread ) has been active milliseco ...

  5. NOIP2005题解

    传送门 考查题型 dp 模拟 贪心 T1 谁拿了最多的奖学金 题目描述 某校的惯例是在每学期的期末考试之后发放奖学金.发放的奖学金共有五种,获取的条件各自不同: 1) 院士奖学金,每人8000元,期末 ...

  6. 148D

    概率dp+记忆化搜索 dp[i][j][0]表示当前公主走公主赢的概率,dp[i][j][1]表示当前龙走公主赢的概率,然后剩下的就是一些细节的讨论,记忆化搜索很方便 #include<bits ...

  7. HTTP Status 500 - javax.servlet.ServletException: java.lang.NoClassDefFoundError: junit/framework/Test解决方法

    java代码 package webViewer; import java.io.*; import junit.framework.Test; import com.aspose.words.*; ...

  8. Swift异常处理的try?与try!

    首先要明白抛出异常后异常的运动:异常被抛出后,中断整个处理,异常不断向外层(范围)传递,直到遇到catch代码块群,会与catch代码块的条件进行匹配,匹配符合则进入此代码块处理.如果遇到没有条件的c ...

  9. DLL分配的内存如何在EXE里面释放

    总结下面几个要点: 1. 保证内存分配和清除的统一性:如果一个DLL提供一个能够分配内存的函数,那么这个DLL同时应该提供一个函数释放这些内存.数据的创建和清除应该在同一个层次上. 曾经遇到过这样的例 ...

  10. 793. Preimage Size of Factorial Zeroes Function

    Let f(x) be the number of zeroes at the end of x!. (Recall that x! = 1 * 2 * 3 * ... * x, and by con ...