apache / incubator-hugegraph-doc

HugeGraph Website and Doc
https://hugegraph.apache.org/
Apache License 2.0
65 stars 95 forks source link

docs: update outdated response in vertex api #259

Closed liuxiaocs7 closed 1 year ago

liuxiaocs7 commented 1 year ago

Fix this page: https://hugegraph.apache.org/cn/docs/clients/restful-api/vertex/

  1. Update outdated vertex response
  2. Improve the testing process

Local Tests:

Env: HG-Server depolyed by docker, (ip:port, 192.168.34.164:18080)

schema:

schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("age").asInt().ifNotExist().create();
schema.propertyKey("city").asText().ifNotExist().create();
schema.propertyKey("weight").asDouble().ifNotExist().create();
schema.propertyKey("lang").asText().ifNotExist().create();
schema.propertyKey("price").asDouble().ifNotExist().create();
schema.propertyKey("hobby").asText().valueList().ifNotExist().create();

schema.vertexLabel("person").properties("name", "age", "city", "weight", "hobby").primaryKeys("name").nullableKeys("age", "city", "weight", "hobby").ifNotExist().create();
schema.vertexLabel("software").properties("name", "lang", "price").primaryKeys("name").nullableKeys("lang", "price").ifNotExist().create();

schema.indexLabel("personByAge").onV("person").by("age").range().ifNotExist().create();

1 Create a vertex

curl -i -H "Content-Type: application/json" -d '{"label":"person","properties":{"name":"marko","age":29}}' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices

response:

curl -i -H "Content-Type: application/json" -d '{"label":"person","properties":{"name":"marko","age":29}}' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices
HTTP/1.1 201 Created
Content-Length: 88
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

{"id":"1:marko","label":"person","type":"vertex","properties":{"name":"marko","age":29}}

2 Create multiple vertices

curl -i -H "Content-Type: application/json" -d '[{"label":"person","properties":{"name":"marko","age":29}},{"label":"software","properties":{"name":"ripple","lang":"java","price":199}}]' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/batch

response:

curl -i -H "Content-Type: application/json" -d '[{"label":"person","properties":{"name":"marko","age":29}},{"label":"software","properties":{"name":"ripple","lang":"java","price":199}}]' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/batch
HTTP/1.1 201 Created
Content-Length: 22
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

["1:marko","2:ripple"]

3 Update vertex properties

curl -i -X PUT -H "Content-Type: application/json" -d '{"label":"person","properties":{"age":30,"city":"Beijing"}}' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/\"1:marko\"?action=append

response:

curl -i -X PUT -H "Content-Type: application/json" -d '{"label":"person","properties":{"age":30,"city":"Beijing"}}' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/\"1:marko\"?action=append
HTTP/1.1 200 OK
Content-Length: 105
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

{"id":"1:marko","label":"person","type":"vertex","properties":{"name":"marko","age":30,"city":"Beijing"}}

4 Batch Update Vertex Properties

add some verticesfor test:

curl -i -H "Content-Type: application/json" -d '[{"label":"person","properties":{"name":"josh","age":32,"city":"Beijing","weight":0.1,"hobby":["reading","football"]}},{"label":"software","properties":{"name":"lop","lang":"java","price":328}}]' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/batch

response:

curl -i -H "Content-Type: application/json" -d '[{"label":"person","properties":{"name":"josh","age":32,"city":"Beijing","weight":0.1,"hobby":["reading","football"]}},{"label":"software","properties":{"name":"lop","lang":"java","price":328}}]' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/batch
HTTP/1.1 201 Created
Content-Length: 18
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

["1:josn","2:lop"]

Batch Update Vertex Properties results:

curl -i -X PUT -H "Content-Type: application/json" -d '{"vertices":[{"label":"software","type":"vertex","properties":{"name":"lop","lang":"c++","price":299}},{"label":"person","type":"vertex","properties":{"name":"josh","city":"Shanghai","weight":0.2,"hobby":["swiming"]}}],"update_strategies":{"price":"BIGGER","age":"OVERRIDE","city":"OVERRIDE","weight":"SUM","hobby":"UNION"},"create_if_not_exist":true}' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/batch

response:

curl -i -X PUT -H "Content-Type: application/json" -d '{"vertices":[{"label":"software","type":"vertex","properties":{"name":"lop","lang":"c++","price":299}},{"label":"person","type":"vertex","properties":{"name":"josh","city":"Shanghai","weight":0.2,"hobby":["swiming"]}}],"update_strategies":{"price":"BIGGER","age":"OVERRIDE","city":"OVERRIDE","weight":"SUM","hobby":"UNION"},"create_if_not_exist":true}' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/batchaph/vertices/batch
HTTP/1.1 200 OK
Content-Length: 278
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

{"vertices":[{"id":"2:lop","label":"software","type":"vertex","properties":{"name":"lop","lang":"c++","price":328.0}},{"id":"1:josh","label":"person","type":"vertex","properties":{"name":"josh","age":32,"city":"Shanghai","weight":0.3,"hobby":["reading","football","swiming"]}}]}

5 Delete Vertex Properties

curl -i -X PUT -H "Content-Type: application/json" -d '{"label":"person","properties":{"city":"Beijing"}}' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/\"1:marko\"?action=eliminate

response:

curl -i -X PUT -H "Content-Type: application/json" -d '{"label":"person","properties":{"city":"Beijing"}}' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/\"1:marko\"?action=eliminate
HTTP/1.1 200 OK
Content-Length: 88
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

{"id":"1:marko","label":"person","type":"vertex","properties":{"name":"marko","age":30}}

6 Get Vertices that Meet the Criteria

curl -i 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices?label=person&properties=\{%22age%22:30\}&limit=1' \
  --compressed

response:

HTTP/1.1 200 OK
Content-Length: 103
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

{"vertices":[{"id":"1:marko","label":"person","type":"vertex","properties":{"name":"marko","age":30}}]}

Paginate through all vertices, retrieve the first page (page without parameter value), limited to 3 records

add some verticesfor test:

curl -i -H "Content-Type: application/json" -d '[{"label":"person","properties":{"name":"peter","age":29,"city":"Shanghai"}},{"label":"person","properties":{"name":"vadas","age":27,"city":"Hongkong"}}]' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/batch

response:

curl -i -H "Content-Type: application/json" -d '[{"label":"person","properties":{"name":"peter","age":29,"city":"Shanghai"}},{"label":"person","properties":{"name":"vadas","age":27,"city":"Hongkong"}}]' http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/batch
HTTP/1.1 201 Created
Content-Length: 21
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

["1:peter","1:vadas"]

Start paging query

curl -i 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices?page&limit=3' \
  --compressed

response:

curl -i 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices?page&limit=3' \
  --compressed
HTTP/1.1 200 OK
Content-Length: 227
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

{"vertices":[{"id":"2:lop","label":"software","type":"vertex","properties":{"name":"lop","lang":"c++","price":328.0}},{"id":"1:josh","label":"person","type":"vertex","properties":{"name":"josh","age":32,"city":"Shanghai","weight":0.3,"hobby":["reading","football","swiming"]}},{"id":"1:marko","label":"person","type":"vertex","properties":{"name":"marko","age":30}}],"page": "CIYxOnBldGVyAAAAAAAAAAM="}

search next page results:

curl -i 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices?page=CIYxOnBldGVyAAAAAAAAAAM=&limit=3' \
  --compressed

response:

curl -i 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices?page=CIYxOnBldGVyAAAAAAAAAAM=&limit=3' \
  --compressed
HTTP/1.1 200 OK
Content-Length: 186
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

{"vertices":[{"id":"1:peter","label":"person","type":"vertex","properties":{"name":"peter","age":29,"city":"Shanghai"}},{"id":"1:vadas","label":"person","type":"vertex","properties":{"name":"vadas","age":27,"city":"Hongkong"}},{"id":"2:ripple","label":"software","type":"vertex","properties":{"name":"ripple","lang":"java","price":199.0}}],"page": null}

7 Retrieve Vertex by ID

curl -i 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/%221:marko%22'

response:

curl -i 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/%221:marko%22'
HTTP/1.1 200 OK
Content-Length: 88
Connection: keep-alive
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

{"id":"1:marko","label":"person","type":"vertex","properties":{"name":"marko","age":30}}

Delete the vertex based on ID only.

curl -i -X DELETE 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/%221:marko%22'

response:

curl -i -X DELETE 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/%221:marko%22'
HTTP/1.1 204 No Content
Connection: keep-alive
Keep-Alive: timeout=4
Proxy-Connection: keep-alive

Delete Vertex by Label+ID

curl -i -X DELETE 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/%221:marko%22?label=person'

response:

curl -i -X DELETE 'http://192.168.34.164:18080/graphs/hugegraph/graph/vertices/%221:marko%22?label=person'
HTTP/1.1 204 No Content
Connection: keep-alive
Keep-Alive: timeout=4
Proxy-Connection: keep-alive