Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update outdated response in vertex api #259

Merged
merged 8 commits into from
Jun 4, 2023

Conversation

liuxiaocs7
Copy link
Member

@liuxiaocs7 liuxiaocs7 commented Jun 2, 2023

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

@liuxiaocs7 liuxiaocs7 changed the title docs: update vertex response docs: update outdated vertex response Jun 2, 2023
@liuxiaocs7 liuxiaocs7 changed the title docs: update outdated vertex response docs: update outdated response in vertex api Jun 2, 2023
Copy link
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it's nice to use GPT/New Bing to enhance the english/chinese typo problem.

Just past the url/phrase into it, ask for the improvement, then it will give us a string of suggestions

content/cn/docs/clients/restful-api/vertex.md Outdated Show resolved Hide resolved
content/cn/docs/clients/restful-api/vertex.md Outdated Show resolved Hide resolved
imbajin
imbajin previously approved these changes Jun 3, 2023
Copy link
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is a nice example for others to refer/improve the outdated doc

Copy link
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement, could also add the (basic) pic/steps for others to refer~

@imbajin imbajin merged commit 37a1cb5 into apache:master Jun 4, 2023
1 check passed
github-actions bot pushed a commit that referenced this pull request Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants