mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-15 09:26:38 +00:00
6d81e3841a
* Allow text/plain content type descriptor for json formatted content body. Refactored duplicated encode/decode functions for rest api * Fix relay endpoint decodings of content bodies to accept text/plain * Added support for content body decoder for checking media type if additional parameters are present * Fix wrong usage of ContentTypeData - appeared only for tests
50 lines
2.4 KiB
Nim
50 lines
2.4 KiB
Nim
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
|
|
../../../waku_core,
|
|
../serdes,
|
|
../responses,
|
|
../rest_serdes,
|
|
./types
|
|
|
|
export types
|
|
|
|
|
|
logScope:
|
|
topics = "waku node rest client"
|
|
|
|
|
|
proc encodeBytes*(value: seq[PubSubTopic],
|
|
contentType: string): RestResult[seq[byte]] =
|
|
return encodeBytesOf(value, contentType)
|
|
|
|
# TODO: Check how we can use a constant to set the method endpoint (improve "rest" pragma under nim-presto)
|
|
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.}
|
|
|
|
# TODO: Check how we can use a constant to set the method endpoint (improve "rest" pragma under nim-presto)
|
|
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.}
|
|
|
|
proc encodeBytes*(value: RelayPostMessagesRequest,
|
|
contentType: string): RestResult[seq[byte]] =
|
|
return encodeBytesOf(value, contentType)
|
|
|
|
# TODO: Check how we can use a constant to set the method endpoint (improve "rest" pragma under nim-presto)
|
|
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.}
|
|
|
|
# TODO: Check how we can use a constant to set the method endpoint (improve "rest" pragma under nim-presto)
|
|
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.}
|