Skip to content

Commit

Permalink
Add the first 3 endpoints to mdbook docs (#41)
Browse files Browse the repository at this point in the history
* add the first 3 endpoints to mdbook docs

* use localhost, not internal fly dns hostname

* consistent slashes
  • Loading branch information
catflydotio authored Sep 8, 2023
1 parent 241c807 commit 8e78f9c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
8 changes: 4 additions & 4 deletions doc/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
- [Templates]()

# Reference
- [API]()
- [POST /v1/exec]()
- [POST /v1/query]()
- [POST /v1/subscriptions]()
- [API](api/README.md)
- [POST /v1/transactions](api/transactions.md)
- [POST /v1/queries](api/queries.md)
- [POST /v1/subscriptions](api/subscriptions.md)
- [Command-line Interface](cli/README.md)
- [agent]()
- [backup](cli/backup.md)
Expand Down
7 changes: 7 additions & 0 deletions doc/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## API

Each running Corrosion agent hosts a RESTful HTTP API for interacting with the cluster's synchronized database. Endpoints accept SQL statements in a JSON body, for versatility.

- [POST /v1/transactions](transactions.md) for writes
- [POST /v1/queries](queries.md) for reads
- [POST /v1/subscriptions](subscriptions.md) to receive streaming updates for a desired query
20 changes: 20 additions & 0 deletions doc/api/queries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## POST /v1/queries

Read from the Corrosion database. The `/v1/queries` endpoint accepts a single SQL statement in JSON format.

### Sample request
```
curl http://localhost:8080/v1/queries \
-H "content-type: application/json" \
-d "\"SELECT sandwich FROM sandwiches\""
```

### Sample response
```json
{"columns":["sandwich"]}
{"row":[1,["burger"]]}
{"row":[2,["ham"]]}
{"row":[3,["grilled cheese"]]}
{"row":[4,["brie and cranberry"]]}
{"eoq":{"time":5e-8}}
```
28 changes: 28 additions & 0 deletions doc/api/subscriptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# POST /v1/subscriptions

Start receiving updates for a desired SQL query. The `/v1/subscriptions` endpoint accepts a single SQL statement in JSON format.
The Corrosion agent responds with an HTML stream that notifies of any changes to the response to this query.

### Sample request
```
curl http://localhost:8080/v1/subscriptions \
-H "content-type: application/json" \
-d "\"SELECT sandwich FROM sw\""
```

### Sample response

```json
{"columns":["sandwich"]}
{"row":[1,["shiitake"]]}
{"row":[2,["ham"]]}
{"row":[3,["grilled cheese"]]}
{"row":[4,["brie and cranberry"]]}
{"eoq":{"time":8e-8}}
{"change":["update",2,["smoked meat"]]}
{"change":["update",1,["smoked meat"]]}
{"change":["update",2,["ham"]]}
{"change":["update",1,["burger"]]}
{"change":["update",2,["smoked meat"]]}
...
```
15 changes: 15 additions & 0 deletions doc/api/transactions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## POST /v1/transactions

Write changes to the Corrosion database for propagation through the cluster. The `/v1/transactions` endpoint accepts a JSON list of SQL statements.

### Sample request
```
curl http://localhost:8080/v1/transactions \
-H "content-type: application/json" \
-d "[\"INSERT OR IGNORE INTO sandwiches (pk, sandwich) VALUES (3, 'brie and cranberry')\"]"
```

### Sample response
```json
{"results":[{"rows_affected":1,"time":0.000027208}],"time":0.000300708}%
```

0 comments on commit 8e78f9c

Please sign in to comment.