2023-02-13 14:22:24 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
import
|
|
|
|
std/sets,
|
|
|
|
stew/byteutils,
|
|
|
|
chronicles,
|
|
|
|
json_serialization,
|
|
|
|
json_serialization/std/options,
|
|
|
|
presto/[route, client, common]
|
|
|
|
import
|
2023-04-19 11:29:23 +00:00
|
|
|
../../../waku_core,
|
2023-02-13 14:22:24 +00:00
|
|
|
../serdes,
|
|
|
|
../responses,
|
2023-11-14 15:59:53 +00:00
|
|
|
../rest_serdes,
|
2023-02-13 14:22:24 +00:00
|
|
|
./types
|
|
|
|
|
|
|
|
export types
|
|
|
|
|
|
|
|
|
|
|
|
logScope:
|
|
|
|
topics = "waku node rest client"
|
|
|
|
|
|
|
|
|
|
|
|
proc encodeBytes*(value: seq[PubSubTopic],
|
|
|
|
contentType: string): RestResult[seq[byte]] =
|
2023-11-14 15:59:53 +00:00
|
|
|
return encodeBytesOf(value, contentType)
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
# TODO: Check how we can use a constant to set the method endpoint (improve "rest" pragma under nim-presto)
|
2023-09-26 19:53:46 +00:00
|
|
|
proc relayPostSubscriptionsV1*(body: seq[PubsubTopic]): RestResponse[string] {.rest, endpoint: "/relay/v1/subscriptions", meth: HttpMethod.MethodPost.}
|
|
|
|
proc relayPostAutoSubscriptionsV1*(body: seq[ContentTopic]): RestResponse[string] {.rest, endpoint: "/relay/v1/auto/subscriptions", meth: HttpMethod.MethodPost.}
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
# TODO: Check how we can use a constant to set the method endpoint (improve "rest" pragma under nim-presto)
|
2023-09-26 19:53:46 +00:00
|
|
|
proc relayDeleteSubscriptionsV1*(body: seq[PubsubTopic]): RestResponse[string] {.rest, endpoint: "/relay/v1/subscriptions", meth: HttpMethod.MethodDelete.}
|
|
|
|
proc relayDeleteAutoSubscriptionsV1*(body: seq[ContentTopic]): RestResponse[string] {.rest, endpoint: "/relay/v1/auto/subscriptions", meth: HttpMethod.MethodDelete.}
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
proc encodeBytes*(value: RelayPostMessagesRequest,
|
|
|
|
contentType: string): RestResult[seq[byte]] =
|
2023-11-14 15:59:53 +00:00
|
|
|
return encodeBytesOf(value, contentType)
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
# TODO: Check how we can use a constant to set the method endpoint (improve "rest" pragma under nim-presto)
|
2023-09-26 19:53:46 +00:00
|
|
|
proc relayGetMessagesV1*(pubsubTopic: string): RestResponse[RelayGetMessagesResponse] {.rest, endpoint: "/relay/v1/messages/{pubsubTopic}", meth: HttpMethod.MethodGet.}
|
|
|
|
proc relayGetAutoMessagesV1*(contentTopic: string): RestResponse[RelayGetMessagesResponse] {.rest, endpoint: "/relay/v1/auto/messages/{contentTopic}", meth: HttpMethod.MethodGet.}
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
# TODO: Check how we can use a constant to set the method endpoint (improve "rest" pragma under nim-presto)
|
2023-09-26 19:53:46 +00:00
|
|
|
proc relayPostMessagesV1*(pubsubTopic: string, body: RelayPostMessagesRequest): RestResponse[string] {.rest, endpoint: "/relay/v1/messages/{pubsubTopic}", meth: HttpMethod.MethodPost.}
|
|
|
|
proc relayPostAutoMessagesV1*(body: RelayPostMessagesRequest): RestResponse[string] {.rest, endpoint: "/relay/v1/auto/messages", meth: HttpMethod.MethodPost.}
|