Skip to content

Commit

Permalink
feat(rest-api-store): new rest api to retrieve store waku messages (#…
Browse files Browse the repository at this point in the history
…1611)

* feat: new rest api based on the current store json-rpc api and
following the same structure as the current relay rest api.

* feat: the store api attend GET requests to retrieve historical messages

* feat: unit tests.

* feat: allow return message to rest-client in case error (4XX or 5XX)

* chore: always allow to call the store api endpoints (only rest) without explicit storenode (#1575)
  • Loading branch information
Ivansete-status committed Apr 4, 2023
1 parent 4066b74 commit 791ecb6
Show file tree
Hide file tree
Showing 10 changed files with 1,488 additions and 24 deletions.
4 changes: 4 additions & 0 deletions apps/wakunode2/wakunode2_setup_rest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import
../../waku/v2/node/rest/debug/handlers as debug_api,
../../waku/v2/node/rest/relay/handlers as relay_api,
../../waku/v2/node/rest/relay/topic_cache,
../../waku/v2/node/rest/store/handlers as store_api,
./config


Expand All @@ -36,5 +37,8 @@ proc startRestServer*(node: WakuNode, address: ValidIpAddress, port: Port, conf:
let relayCache = TopicCache.init(capacity=conf.restRelayCacheCapacity)
installRelayApiHandlers(server.router, node, relayCache)

## Store REST API
installStoreApiHandlers(server.router, node)

server.start()
info "Starting REST HTTP server", url = "http://" & $address & ":" & $port & "/"
1 change: 0 additions & 1 deletion apps/wakunode2/wakunode2_setup_rpc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ proc startRpcServer*(node: WakuNode, address: ValidIpAddress, port: Port, conf:
let filterMessageCache = filter_api.MessageCache.init(capacity=30)
installFilterApiHandlers(node, server, filterMessageCache)

# TODO: Move to setup protocols proc
if conf.storenode != "":
installStoreApiHandlers(node, server)

Expand Down
32 changes: 17 additions & 15 deletions docs/api/v2/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,28 @@ This API is divided in different _namespaces_ which group a set of resources:
| `/admin` | Privileged access to the internal operations of the node. |
| `/private` | Provides functionality to encrypt/decrypt `WakuMessage` payloads using either symmetric or asymmetric cryptography. This allows backwards compatibility with Waku v1 nodes. |

The full HTTP REST API documentation can be found here: [TBD]()

### API Specification

The HTTP REST API has been designed following the OpenAPI 3.0.3 standard specification format. The OpenAPI specification file can be found here: [TBD]()
The HTTP REST API has been designed following the OpenAPI 3.0.3 standard specification format. The OpenAPI specification files can be found here:

| Namespace | OpenAPI file |
------------|--------------
| `/debug` | [openapi.yaml](https://github.com/waku-org/nwaku/blob/master/waku/v2/node/rest/debug/openapi.yaml) |
| `/relay` | [openapi.yaml](https://github.com/waku-org/nwaku/blob/master/waku/v2/node/rest/relay/openapi.yaml) |
| `/store` | [openapi.yaml](https://github.com/waku-org/nwaku/blob/master/waku/v2/node/rest/store/openapi.yaml) |
| `/filter` | [openapi.yaml](https://github.com/waku-org/nwaku/blob/master/waku/v2/node/rest/filter/openapi.yaml) |

The OpenAPI files can be analysed online with [Redocly](https://redocly.github.io/redoc/)

Check the [OpenAPI Tools](https://openapi.tools/) site for the right tool for you (e.g. REST API client generator)

A particular OpenAPI spec can be easily imported into [Postman](https://www.postman.com/downloads/)
1. Open Postman.
2. Click on File -> Import...
2. Load the openapi.yaml of interest, stored in your computer.
3. Then, requests can be made from within the 'Collections' section.


### Usage example

Expand All @@ -40,16 +54,4 @@ curl http://localhost:8645/debug/v1/info -s | jq


### Node configuration

A subset of the node configuration can be used to modify the behaviour of the HTTP REST API. These are the relevant command line options:

| CLI option | Description | Default value |
|------------|-------------|---------------|
|`--rest` | Enable Waku REST HTTP server. | `false` |
|`--rest-address` | Listening address of the REST HTTP server. | `127.0.0.1` |
|`--rest-port` | Listening port of the REST HTTP server. | `8645` |
|`--rest-relay-cache-capacity` | Capacity of the Relay REST API message cache. | `30` |
|`--rest-admin` | Enable access to REST HTTP Admin API. | `false` |
|`--rest-private` | Enable access to REST HTTP Private API. | `false` |

Note that these command line options have their counterpart option in the node configuration file.
Find details [here](https://github.com/waku-org/nwaku/tree/master/docs/operators/how-to/configure-rest-api.md)
20 changes: 20 additions & 0 deletions docs/operators/how-to/configure-rest-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Node configuration

A subset of the node configuration can be used to modify the behaviour of the HTTP REST API. These are the relevant command line options:

| CLI option | Description | Default value |
|------------|-------------|---------------|
|`--rest` | Enable Waku REST HTTP server. | `false` |
|`--rest-address` | Listening address of the REST HTTP server. | `127.0.0.1` |
|`--rest-port` | Listening port of the REST HTTP server. | `8645` |
|`--rest-relay-cache-capacity` | Capacity of the Relay REST API message cache. | `30` |
|`--rest-admin` | Enable access to REST HTTP Admin API. | `false` |
|`--rest-private` | Enable access to REST HTTP Private API. | `false` |

Note that these command line options have their counterpart option in the node configuration file.

Example:

```shell
wakunode2 --rest=true
```
Loading

0 comments on commit 791ecb6

Please sign in to comment.