据笔者所知,在写本书时,现在还没有正式的小精灵语言绑定支持对于Ruby程序员来说是可用的。这是一个非常棒的例子,向我们说明:如何使用一小段代码,一名Rubyt程序员就可以连接到小精灵服务器并执行小精灵查询。
As far as I know, at time of writing, there is currently no formal Gremlin language binding support
available for Ruby programmers. This is therefore a perfect use case to show how, using a small
amount of code, a Ruby programmer can connect to a Gremlin Server and issue Gremlin Queries.
Ruby例子的源代码,gremlin-client-http.rb,如下所示,可以在样例代码目录中找到 https://github.com/krlawrence/graph/tree/master/sample-code
The source code for the Ruby example, gremlin-client-http.rb, as shown below, is
available in the sample-code folder. https://github.com/krlawrence/graph/tree/
master/sample-code
下面的代码代表了一个完整的,独立的Ruby应用程序。它使用了标准的Ruby库。不需要额外的Ruby Gems 或者第三方的库。这个例子说明了如何连接到运行在您本地机器上的小精灵服务器。它打包了一个HTTP POST 请求,并发送到小精灵服务器。HTTP请求的主体是用JSON编码的。
The code below represents a complete, standalone Ruby application. It uses the standard Ruby
libraries. No additional Ruby Gems or third party libraries should be required. The example as
shown connects to a Gremlin Server running on your local machine. It packages up an HTTP POST
request and sends it to the Gremlin Server. The body of the HTTP request is encoded as JSON.
这是返回的输出,笔者运行程序时使用的Ruby版本是2.3.1.如您所见,结果主体部分包含了一个JSON对象,这和我们前边使用curl命令发起请求得到的结果是一样。
Here is the output that was returned when I ran the program using Ruby version 2.3.1. As you can
see the result body contains a JSON object just as when we issued requests using the curl command
earlier.
浙公网安备 33010602011771号