nwaku/docs/api/v2/node.md
Oskar Thorén f828736e1c
Add support for WakuMessage and merge publish function (#122)
* Add WakuMessage type

* Add WakuMessage encoding and decoding

Also clean up waku_types module and imports

* Clean up waku_relay module

Imports, remove old text test, make fields and functions public, format.

* Publish WakuMessage

Also fix type mismatch in RPC

* Make publish work in examples, node and protocol

* Parse protobuf content in examples

* Update docs

* Update waku/node/v2/waku_types.nim

* Fix compilation error and disable out of date waku test

Co-authored-by: Kim De Mey <kim.demey@gmail.com>
2020-09-01 17:20:38 +02:00

66 lines
2.2 KiB
Markdown

# Waku APIs
## Nim API
The Nim Waku API consist of five methods. Some of them have different arity
depending on what privacy/bandwidth trade-off the consumer wants to make. These
five method are:
1. **Init** - create and start a node.
2. **Subscribe** - to a topic or a specific content filter.
3. **Unsubscribe** - to a topic or a specific content filter.
4. **Publish** - to a topic, or a topic and a specific content filter.
5. **Query** - for historical messages.
```Nim
proc init*(T: type WakuNode, conf: WakuNodeConf): Future[T]
## Creates and starts a Waku node.
##
## Status: Implemented.
method subscribe*(w: WakuNode, topic: Topic, handler: TopicHandler)
## Subscribes to a PubSub topic. Triggers handler when receiving messages on
## this topic. TopicHandler is a method that takes a topic and some data.
##
## NOTE The data field SHOULD be decoded as a WakuMessage.
## Status: Implemented.
method subscribe*(w: WakuNode, contentFilter: ContentFilter, handler: ContentFilterHandler)
## Subscribes to a ContentFilter. Triggers handler when receiving messages on
## this content filter. ContentFilter is a method that takes some content
## filter, specifically with `ContentTopic`, and a `Message`. The `Message`
## has to match the `ContentTopic`.
## Status: Not yet implemented.
## TODO Implement as wrapper around `waku_filter` and `subscribe` above.
method unsubscribe*(w: WakuNode, topic: Topic)
## Unsubscribe from a topic.
##
## Status: Not yet implemented.
## TODO Implement.
method unsubscribe*(w: WakuNode, contentFilter: ContentFilter)
## Unsubscribe from a content filter.
##
## Status: Not yet implemented.
## TODO Implement.
method publish*(w: WakuNode, topic: Topic, message: WakuMessage)
## Publish a `WakuMessage` to a PubSub topic. `WakuMessage` should contain a
## `contentTopic` field for light node functionality. This field may be also
## be omitted.
##
## Status: Implemented.
method query*(w: WakuNode, query: HistoryQuery): HistoryResponse
## Queries for historical messages.
##
## Status: Not yet implemented.
## TODO Implement as wrapper around `waku_store` and send RPC.
```
## JSON RPC
### TODO To specify