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

Update README #31

Merged
merged 4 commits into from
Jul 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 58 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,23 @@ $ ./nebula-httpd

## Required

- Go 11+
- Go 1.13+
- [beego](https://beego.me/)

## User Guide

#### API Definition
### API Definition

| Name | Path | Method |
|------------|--------------------|--------|
| connect | /api/db/connect | POST |
| exec | /api/db/exec | POST |
| disconnect | /api/db/disconnect | POST |

> Connect API
#### Connect API ####

The request json body

The requested json body
```json
{
"username": "user",
Expand All @@ -40,7 +42,8 @@ The requested json body
"port": 9669
}
```
The description of the parameters is as follows.

The description of the parameters is as follows:

| Field | Description |
|----------|-----------------------------------------------------------------------------------------------------------------------------|
Expand All @@ -50,7 +53,15 @@ The description of the parameters is as follows.
| port | Sets the port number of the graphd service. The default port number is 9669. |

```bash
$ curl -i -X POST -d '{"username":"user","password":"password","address":"192.168.8.26","port":9669}' http://127.0.0.1:8080/api/db/connect
$ curl -i \
-X POST \
-d '{"username":"user","password":"password","address":"192.168.8.26","port":9669}' \
http://127.0.0.1:8080/api/db/connect
```

response:

```
HTTP/1.1 200 OK
Content-Length: 100
Content-Type: application/json; charset=utf-8
Expand All @@ -69,44 +80,63 @@ Date: Fri, 02 Apr 2021 08:49:18 GMT

Notice:

The response data nsid "5e18fa40-5343-422f-84e3-e7f9cad6b735" is encoded by HMAC-SH256 encryption algorithmso it's not the same as what you get from a cookie.
If you connect the graphd service succeed, remember to save the *NSID*, it's important for the *exec api* to execute nGQL.
If you restart the gateway server, all authenticated session will be lost, please noticed.
The response data nsid `5e18fa40-5343-422f-84e3-e7f9cad6b735` is encoded by HMAC-SH256 encryption algorithm, so it's not the same as what you get from a cookie.
If you connect to the graphd service successfully, remember to save the *NSID* locally, which is important for the *exec* api to execute nGQL.
If you restart the gateway server, all authenticated session will be lost, please be aware of this.

> Exec API
#### Exec API ####

The requested json body

```json
{
"gql": "show spaces;"
"gql": "show spaces;"
}
```
The request header is necessary to request exec api, cookies must be set to get results.

**Cookie** is required in the request header to request `exec` api.


```bash
$ curl -H "Cookie: SameSite=None; nsid=bec2e665ba62a13554b617d70de8b9b9" -H "nsid: bec2e665ba62a13554b617d70de8b9b9" -X POST -d '{"gql": "show spaces;"}' http://127.0.0.1:8080/api/db/exec
{
"code": 0,
"data": {
"headers": [
"Name"
],
"tables": [
{
"Name": "nba"
}
],
"timeCost": 4232
},
"message": ""
$ curl -X POST \
-H "Cookie: SameSite=None; nsid=bec2e665ba62a13554b617d70de8b9b9" \
-H "nsid: bec2e665ba62a13554b617d70de8b9b9" \
-d '{"gql": "show spaces;"}' \
http://127.0.0.1:8080/api/db/exec
```

> Disconnect API
response:

```json
{
"code": 0,
"data": {
"headers": [
"Name"
],
"tables": [
{
"Name": "nba"
}
],
"timeCost": 4232
},
"message": ""
}
```

#### Disconnect API ####

```bash
$ curl -X POST http://127.0.0.1:8080/api/db/disconnect
```

response:

```json
{
"code": 0,
"data": null,
"message": "Disconnect successfully"
}
```