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) (#1630)

* 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)

* feat: always mounting the current node as storenode client
  • Loading branch information
Ivansete-status committed Apr 6, 2023
1 parent 9dadc1f commit b2acb54
Show file tree
Hide file tree
Showing 13 changed files with 1,505 additions and 27 deletions.
2 changes: 1 addition & 1 deletion apps/wakunode2/wakunode2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@ proc setupProtocols(node: WakuNode, conf: WakuNodeConf,
executeMessageRetentionPolicy(node)
startMessageRetentionPolicyPeriodicTask(node, interval=WakuArchiveDefaultRetentionPolicyInterval)

mountStoreClient(node)
if conf.storenode != "":
try:
mountStoreClient(node)
let storenode = parseRemotePeerInfo(conf.storenode)
node.peerManager.addServicePeer(storenode, WakuStoreCodec)
except CatchableError:
Expand Down
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 & "/"
33 changes: 18 additions & 15 deletions docs/api/v2/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,29 @@ 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 +55,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)
23 changes: 23 additions & 0 deletions docs/operators/how-to/configure-rest-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# Configure a REST API node

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
```
3 changes: 2 additions & 1 deletion docs/operators/how-to/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ The following options are available:

## Configuration use cases

This an index of tutorials explaining how to configure your nwaku node for different use cases.
This is an index of tutorials explaining how to configure your nwaku node for different use cases.

1. [Connect to other peers](./connect.md)
2. [Configure a domain name](./configure-domain.md)
Expand All @@ -133,3 +133,4 @@ This an index of tutorials explaining how to configure your nwaku node for diffe
5. [Generate and configure a node key](./configure-key.md)
6. [Configure websocket transport](./configure-websocket.md)
7. [Run nwaku with rate limiting enabled](./run-with-rln.md)
8. [Configure a REST API node](./configure-rest-api.md)
3 changes: 2 additions & 1 deletion tests/all_tests_v2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ import
./v2/wakunode_rest/test_rest_debug_serdes,
./v2/wakunode_rest/test_rest_relay,
./v2/wakunode_rest/test_rest_relay_serdes,
./v2/wakunode_rest/test_rest_serdes
./v2/wakunode_rest/test_rest_serdes,
./v2/wakunode_rest/test_rest_store


## Apps
Expand Down

0 comments on commit b2acb54

Please sign in to comment.